Пример #1
0
        private void Apply(IEditorPlugin plugin)
        {
            Range _line = txt.GetLine(txt.Selection.Start.iLine);

            SelInfo _selInfo = new SelInfo()
            {
                Text         = txt.Text,
                SelectedText = txt.SelectedText,
                CurrentLine  = _line.Text
            };

            try
            {
                if (!plugin.OmitResult)
                {
                    plugin.Apply(_selInfo);
                    txt.SelectedText = _selInfo.SelectedText;
                }
                else
                {
                    plugin.Apply(_selInfo);
                }
            }
            catch (Exception)
            {
            }
        }
Пример #2
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Get information about the selection
		/// </summary>
		/// <param name="fEnd"><c>true</c> to get information about the end of the selection,
		/// otherwise <c>false</c>.</param>
		/// <returns><c>true</c> if information retrieved, otherwise <c>false</c>.</returns>
		/// -----------------------------------------------------------------------------------
		private bool GetSelEndInfo(bool fEnd)
		{
			int i = fEnd ? 1 : 0;
			int cvsli = m_vwSel.CLevels(fEnd) - 1;
			//Review TE Team (JT-JH): We changed this from if (cvsli <= 0). We're guessing there just isn't any 0 cases in TE?
			if (cvsli < 0)
				cvsli = 0;
				//return false;

			if (m_selInfo[i] == null)
				m_selInfo[i] = new SelInfo();

			using (ArrayPtr prgvsli = MarshalEx.ArrayToNative<SelLevInfo>(cvsli))
			{
				m_vwSel.AllSelEndInfo(fEnd, out m_selInfo[i].ihvoRoot, cvsli, prgvsli,
					out m_selInfo[i].tagTextProp, out m_selInfo[i].cpropPrevious, out m_selInfo[i].ich,
					out m_selInfo[i].ws, out m_selInfo[i].fAssocPrev, out m_selInfo[i].ttpSelProps);
				m_selInfo[i].rgvsli = MarshalEx.NativeToArray<SelLevInfo>(prgvsli, cvsli);
			}

			if (fEnd)
				m_fEndSet = true;
			return true;
		}
Пример #3
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Copy constructor
		/// </summary>
		/// <param name="src">The source object</param>
		/// ------------------------------------------------------------------------------------
		public SelectionHelper(SelectionHelper src)
		{
			m_selInfo[0] = new SelInfo(src.SelectionInfo[0]);
			m_selInfo[1] = new SelInfo(src.SelectionInfo[1]);
			m_iTop = src.m_iTop;
			m_ihvoEnd = src.m_ihvoEnd;
			m_vwSel = src.m_vwSel;
			RootSite = src.RootSite;
			m_fEndSet = src.m_fEndSet;
			m_dyIPTop = src.m_dyIPTop;
		}
Пример #4
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Returns the index used for the appropriate limit type
		/// </summary>
		/// <param name="type">Limit type</param>
		/// <returns>Index</returns>
		/// ------------------------------------------------------------------------------------
		private int GetIndex(SelLimitType type)
		{
			int i;
			switch (type)
			{
				case SelLimitType.Anchor:
					i = 0;
					break;
				case SelLimitType.End:
					i = 1;
					break;
				case SelLimitType.Top:
					i = TopIndex;
					break;
				case SelLimitType.Bottom:
					i = BottomIndex;
					break;
				default:
					throw new ArgumentOutOfRangeException("Got unexpected SelLimitType");
			}
			if (m_selInfo[i] == null)
			{
				SelInfo otherEnd = m_selInfo[i == 0 ? 1 : 0];
				m_selInfo[i] = new SelInfo(otherEnd);
			}
			return i;
		}
Пример #5
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Make a range selection based upon our saved selection info.
		/// NOTE: Installing the selection may trigger side effects that will invalidate the selection.
		/// Callers should check to make sure the selection is still valid before using it.
		/// </summary>
		/// <param name="rootBox"></param>
		/// <param name="fInstall"></param>
		/// <exception cref="Exception">throws if unable to make an end selection</exception>
		/// <returns>a range selection (could become invalid as a side-effect of installing.)</returns>
		/// -----------------------------------------------------------------------------------
		public IVwSelection MakeRangeSelection(IVwRootBox rootBox, bool fInstall)
		{
			int iAnchor = 0;
			int iEnd = 1;
			if (!m_fEndSet)
			{	// No end information set, so use iAnchor as end
				iEnd = iAnchor;
			}
			if (m_selInfo[iEnd] == null)
			{
				m_selInfo[iEnd] = new SelInfo(m_selInfo[iAnchor]);
			}

			// This change was proposed in change set 37331 but it's not clear what crash sometimes happens if it's not done.
			// Apparently it doesn't always crash because some TeDllTests fail if we do this.
			// Don't make a selection if the property indicates not to: see comment about -2 in InterlinDocForAnalysis.HandleSelectionChange
			//if (m_selInfo[iAnchor].tagTextProp == -2)
			//    return null;  // crashes if allowed to continue

			// we want to pass fInstall=false to MakeTextSelection so that it doesn't notify
			// the RootSite of the selection change.
			IVwSelection vwSelAnchor;
			try
			{
				vwSelAnchor = rootBox.MakeTextSelection(
					m_selInfo[iAnchor].ihvoRoot, m_selInfo[iAnchor].rgvsli.Length,
					m_selInfo[iAnchor].rgvsli, m_selInfo[iAnchor].tagTextProp,
					m_selInfo[iAnchor].cpropPrevious, m_selInfo[iAnchor].ich, m_selInfo[iAnchor].ich,
					m_selInfo[iAnchor].ws, m_selInfo[iAnchor].fAssocPrev, m_selInfo[iAnchor].ihvoEnd,
					null, false);
			}
			catch (Exception e)
			{
				Debug.Assert(m_selInfo[iEnd].rgvsli.Length > 0 || m_selInfo[iAnchor].rgvsli.Length == 0,
					"Making the anchor selection failed, this is probably an empty editable field.");
				throw;
			}
			IVwSelection vwSelEnd;
			try
			{
				vwSelEnd = rootBox.MakeTextSelection(
					m_selInfo[iEnd].ihvoRoot, m_selInfo[iEnd].rgvsli.Length,
					m_selInfo[iEnd].rgvsli, m_selInfo[iEnd].tagTextProp,
					m_selInfo[iEnd].cpropPrevious, m_selInfo[iEnd].ich, m_selInfo[iEnd].ich,
					m_selInfo[iEnd].ws, m_selInfo[iEnd].fAssocPrev, m_selInfo[iEnd].ihvoEnd,
					null, false);

			}
			catch (Exception)
			{
				Debug.Assert(m_selInfo[iEnd].rgvsli.Length > 0 || m_selInfo[iAnchor].rgvsli.Length == 0,
					"The anchor has rgvsli but the end does not; since making the end selection failed, this is probably a mistake.");
				throw;
			}
			return rootBox.MakeRangeSelection(vwSelAnchor, vwSelEnd, fInstall);
		}
Пример #6
0
			/// --------------------------------------------------------------------------------
			/// <summary>
			/// Copy constructor
			/// </summary>
			/// <param name="src">The source object</param>
			/// --------------------------------------------------------------------------------
			public SelInfo(SelInfo src)
			{
				if (src == null)
					return;

				tagTextProp =  src.tagTextProp;
				ihvoRoot = src.ihvoRoot;
				cpropPrevious = src.cpropPrevious;
				ich = src.ich;
				ws = src.ws;
				fAssocPrev = src.fAssocPrev;
				ihvoEnd = src.ihvoEnd;
				rgvsli = new SelLevInfo[src.rgvsli.Length];
				Array.Copy(src.rgvsli, rgvsli, src.rgvsli.Length);
			}
Пример #7
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Make a range selection based upon our saved selection info.
		/// NOTE: Installing the selection may trigger side effects that will invalidate the selection.
		/// Callers should check to make sure the selection is still valid before using it.
		/// </summary>
		/// <param name="rootBox"></param>
		/// <param name="fInstall"></param>
		/// <returns>a range selection (could become invalid as a side-effect of installing.)</returns>
		/// -----------------------------------------------------------------------------------
		public IVwSelection MakeRangeSelection(IVwRootBox rootBox, bool fInstall)
		{
			int iAnchor = 0;
			int iEnd = 1;
			if (!m_fEndSet)
			{	// No end information set, so use iAnchor as end
				iEnd = iAnchor;
			}
			if (m_selInfo[iEnd] == null)
			{
				m_selInfo[iEnd] = new SelInfo(m_selInfo[iAnchor]);
			}

			// we want to pass fInstall=false to MakeTextSelection so that it doesn't notify
			// the RootSite of the selection change.
			IVwSelection vwSelAnchor = rootBox.MakeTextSelection(
				m_selInfo[iAnchor].ihvoRoot, m_selInfo[iAnchor].rgvsli.Length,
				m_selInfo[iAnchor].rgvsli, m_selInfo[iAnchor].tagTextProp,
				m_selInfo[iAnchor].cpropPrevious, m_selInfo[iAnchor].ich, m_selInfo[iAnchor].ich,
				m_selInfo[iAnchor].ws, m_selInfo[iAnchor].fAssocPrev, m_selInfo[iAnchor].ihvoEnd,
				null, false);
			IVwSelection vwSelEnd = rootBox.MakeTextSelection(
				m_selInfo[iEnd].ihvoRoot, m_selInfo[iEnd].rgvsli.Length,
				m_selInfo[iEnd].rgvsli, m_selInfo[iEnd].tagTextProp,
				m_selInfo[iEnd].cpropPrevious, m_selInfo[iEnd].ich, m_selInfo[iEnd].ich,
				m_selInfo[iEnd].ws, m_selInfo[iEnd].fAssocPrev, m_selInfo[iEnd].ihvoEnd,
				null, false);
			return rootBox.MakeRangeSelection(vwSelAnchor, vwSelEnd, fInstall);
		}
Пример #8
0
        /// <summary>The read dicom tree.</summary>
        /// <param name="avs">The avs.</param>
        /// <param name="result">The result.</param>
        /// <returns>The <see cref="int"/>.</returns>
        /// <exception cref="NotImplementedException"></exception>
        public ErrorType ReadDicomTree(out AVSfield avs, out string result)
        {
            result = null;

            // throw new NotImplementedException();
            string szParam;
            string pSelCopy;
            string pTmp;
            string pszParamName;

            avs = new AVSfield();

            if (this._errorCode == 0)
            {
                return(this._errorCode);
            }

            if (this.SelInfo == null)
            {
                /* Create a TREE */
                this._errorCode = this._dcmTreeReader.CreateTree(out avs, this.DcmInfo);
            }
            else if (string.IsNullOrEmpty(this.ParamName))
            {
                /* Read a modality */
                this._errorCode = this._dcmTreeReader.ReadModality(out avs, this.DcmInfo, this.SelInfo, null);
            }
            else
            {
                /* Return a property (AVSfield or a string */
                if (this.ParamName == "all")
                {
                    /* All properties in an AVSfield */
                    this._errorCode = this._dcmTreeReader.ReadKeys(out avs, this.DcmInfo, this.SelInfo);
                }
                else if (this.ParamName == "fullproperties")
                {
                    /* All properties in an AVSfield, including sequences */
                    this._errorCode = this._dcmTreeReader.ReadFullProperties(out avs, this.DcmInfo, this.SelInfo);
                }
                else if (this.ParamName == "worldxfm" || this.ParamName == "bostonscantosiddonpatient")
                {
                    /* XFM in an AVSfield */
                    if ((this.SelInfo.Modality == ModalityType.DCM_MODALITY_SCAN /*&& SelInfo.bMfScan == 0 */) ||
                        (this.SelInfo.Modality == ModalityType.DCM_MODALITY_DOSE /*&& SelInfo.bMfScan == 0 */))
                    {
                        this._errorCode = this._dcmTreeReader.CacheGetXfm1(out avs, this.SelInfo);
                        if (this._errorCode != 0)
                        {
                            this._errorCode = this._dcmTreeReader.ReadModality(
                                out avs,
                                this.DcmInfo,
                                this.SelInfo,
                                null);
                            if (this._errorCode == 0 /*DCM_E_OK*/)
                            {
                                this._errorCode = this._dcmTreeReader.CacheGetXfm1(out avs, this.SelInfo);

                                /*if (*ppOut)
                                 * {
                                 *  rc = DCM_E_OK;
                                 * }
                                 * else
                                 * {
                                 *  rc = DCM_E_NO_XFM;
                                 * }*/
                            }
                        }
                    }
                    else if (this.SelInfo.Modality == ModalityType.DCM_MODALITY_BEAM)
                    {
                        this._errorCode = this._dcmTreeReader.BeamToWorld(out avs, this.SelInfo);
                        if (this._errorCode == ErrorType.DCM_E_INTERNAL)
                        {
                            // Meaning no cached referenced xfm, here!!
                            AVSfield patientTree;
                            AVSfield Scan_Field;

                            this._errorCode = this._dcmTreeReader.CreateTree(out patientTree, this.DcmInfo);
                            if (this._errorCode == ErrorType.DCM_E_OK)
                            {
                                var scanUrl = ParseInput.CacheGetReferencedScanUrlForBeam(this.SelInfo);
                                this._errorCode = this._dcmTreeReader.ReadModality(
                                    out Scan_Field,
                                    this.DcmInfo,
                                    scanUrl,
                                    null);
                                this._errorCode = this._dcmTreeReader.BeamToWorld(out avs, this.SelInfo);
                            }
                        }

                        if (this._errorCode == ErrorType.DCM_E_NO_XFM)
                        {
                            // Meaning no cached xfm of beam itself, here!!
                            AVSfield Beam_Field;
                            this._errorCode = this._dcmTreeReader.ReadModality(
                                out Beam_Field,
                                this.DcmInfo,
                                this.SelInfo,
                                null);
                            this._errorCode = this._dcmTreeReader.BeamToWorld(out avs, this.SelInfo);
                        }

                        /*if (!*ppOut)
                         * {
                         *  rc = DCM_E_NO_XFM;
                         * }*/
                    }
                    else if (this.SelInfo.Modality == ModalityType.DCM_MODALITY_STRUCTURE)
                    {
                        this._errorCode = this._dcmTreeReader.StructureToWorld(out avs, this.SelInfo);
                    }
                    else
                    {
                        this._errorCode = this._dcmTreeReader.DcmGetDicomToSiddonXfm(out avs);
                    }
                }
                else if (this.ParamName == "gantryxfm" || this.ParamName == "bostonscantosiddonworld")
                {
                    /* XFM in an AVSfield */
                    if ((this.SelInfo.Modality == ModalityType.DCM_MODALITY_SCAN) ||
                        (this.SelInfo.Modality == ModalityType.DCM_MODALITY_DOSE) ||
                        (this.SelInfo.Modality == ModalityType.DCM_MODALITY_BEAM))
                    {
                        this._errorCode = this._dcmTreeReader.CacheGetXfm2(out avs, this.SelInfo);
                        if (this._errorCode != 0)
                        {
                            this._errorCode = this._dcmTreeReader.ReadModality(
                                out avs,
                                this.DcmInfo,
                                this.SelInfo,
                                null);
                            if (this._errorCode == ErrorType.DCM_E_OK)
                            {
                                this._errorCode = this._dcmTreeReader.CacheGetXfm2(out avs, this.SelInfo);

                                /* if (*ppOut)
                                 * {
                                 *  this._errorCode = DCM_E_OK;
                                 * }
                                 * else
                                 * {
                                 *  rc = DCM_E_NO_XFM;
                                 * }*/
                            }
                        }

                        // rc = DCM_E_INTERNAL;
                    }
                    else if (this.SelInfo.Modality == ModalityType.DCM_MODALITY_STRUCTURE)
                    {
                        if (this.SelInfo.Selection.Contains(".scan"))
                        {
                            var index = this.SelInfo.Selection.IndexOf(".scan") + 5;
                            using (
                                var tmpSel = new SelInfo(
                                    out this._errorCode,
                                    this.SelInfo.Selection.Substring(0, index)))
                            {
                                /* Get the XFM of underlying scan */
                                this._errorCode = this._dcmTreeReader.CacheGetXfm2(out avs, tmpSel);
                            }
                        }
                        else
                        {
                            this._errorCode = ErrorType.DCM_E_INTERNAL;
                        }

                        /*if (*ppOut)
                         *  {
                         *      rc = DCM_E_OK;
                         *  }
                         *  else
                         *  {
                         *      rc = DCM_E_INTERNAL;
                         *  }*/
                    }
                    else
                    {
                        this._errorCode = this._dcmTreeReader.DcmGetDicomToSiddonXfm(out avs);
                    }
                }
                else if (this.ParamName == "refbeam")
                {
                    /* The referenced beam of an RTIMAGE */
                    this._errorCode = this._dcmTreeReader.ReadRefBeam(out avs, this.DcmInfo, this.SelInfo);
                }
                else if (this.ParamName == "refbeamworldxfm" || this.ParamName == "refbeambostonscantosiddonpatient")
                {
                    this._errorCode = this._dcmTreeReader.CacheGetXfm1(out avs, this.SelInfo);

                    /* if (*ppOut)
                     * {
                     *  rc = DCM_E_OK;
                     * }
                     * else
                     * {
                     *  rc = DCM_E_NO_DATASET;
                     * }*/
                }
                else if (this.ParamName == "refbeamgantryxfm" || this.ParamName == "refbeambostonscantosiddonworld")
                {
                    this._errorCode = this._dcmTreeReader.CacheGetXfm2(out avs, this.SelInfo);

                    /*if (*ppOut)
                     * {
                     *  rc = DCM_E_OK;
                     * }
                     * else
                     * {
                     *  rc = DCM_E_NO_DATASET;
                     * }*/
                }
                else if (this.ParamName == "matchxfm")
                {
                    this._errorCode = ErrorType.DCM_E_OK;
                }
                else if (this.ParamName == "bitmap")
                {
                    this._errorCode = ErrorType.DCM_E_OK;
                }
                else if (this.ParamName == "directory")
                {
                    result          = string.Empty;
                    this._errorCode = ErrorType.DCM_E_OK;
                }
                else if ((this.SelInfo.Modality == ModalityType.DCM_MODALITY_BEAM) && this.ParamName.Contains("[") &&
                         this.ParamName.Contains("]"))
                {
                    /* Something of an indexed segment within a beam is wanted. It can be:
                     *   - outline[]
                     *   - worldxfm[]
                     *   - bostonscantosiddonpatient[]
                     *   - gantryxfm[]
                     *   - bostonscantosiddonworld[]
                     *   - some_property[]
                     *   Only the last of these returns a string. All the others return a field.
                     */
                    /* For now the XFMs of a segment behave the same as the XFMs of a beam */
                    if (string.Compare(this.ParamName, 0, "worldxfm", 0, 8) == 0 ||
                        string.Compare(this.ParamName, 0, "bostonscantosiddonpatient", 0, 25) == 0)
                    {
                        this._errorCode = this._dcmTreeReader.BeamToWorld(out avs, this.SelInfo);
                    }
                    else if (string.Compare(this.ParamName, 0, "gantryxfm", 0, 9) == 0 ||
                             string.Compare(this.ParamName, 0, "bostonscantosiddonworld", 0, 23) == 0)
                    {
                        this._errorCode = this._dcmTreeReader.CacheGetXfm2(out avs, this.SelInfo);

                        /*if (*ppOut)
                         * {
                         *  rc = DCM_E_OK;
                         * }
                         * else
                         * {
                         *  rc = DCM_E_INTERNAL;
                         * }*/
                    }

                    /* The parameters outline[] behaves the same as ReadModality, but now for
                     *   a specific segment. The parameter edge[] does some additional postprocessing
                     *   in order to return the field edge only.
                     *   All this functionality is solved in CqRtObjects; just pass the parameter to it.
                     */
                    else if (string.Compare(this.ParamName, 0, "outline", 0, 7) == 0)
                    {
                        this._errorCode = this._dcmTreeReader.ReadModality(
                            out avs,
                            this.DcmInfo,
                            this.SelInfo,
                            this.ParamName);
                    }
                    else
                    {
                        this._errorCode = this._dcmTreeReader.GetKey(
                            out result,
                            this.DcmInfo,
                            this.SelInfo,
                            this.ParamName);
                    }
                }
                else
                {
                    this._errorCode = this._dcmTreeReader.GetKey(
                        out result,
                        this.DcmInfo,
                        this.SelInfo,
                        this.ParamName);
                }
            }

            return(this._errorCode);
        }
Пример #9
0
 /// <summary>The parse sel info.</summary>
 /// <param name="selInfo">The sel Info.</param>
 /// <param name="selection">The selection.</param>
 /// <returns>The <see cref="int"/>.</returns>
 public static int ParseSelInfo(SelInfo selInfo, string selection)
 {
     return(0);
 }
Пример #10
0
 /// <summary>The cache get referenced scan url for beam.</summary>
 /// <param name="selInfo">The sel info.</param>
 /// <returns>The <see cref="string"/>.</returns>
 public static SelInfo CacheGetReferencedScanUrlForBeam(SelInfo selInfo)
 {
     return(selInfo);
 }