public BeamLimitingDevicePosition()
        {
            si = new SequenceItem();

            //Add blank RTBeamDeviceType
            CodeString cs = new CodeString();
            cs.Tag.Id = TagHelper.RTBEAM_LIMITING_DEVICE_TYPE;
            si.AddObject(cs);

            //Add blank Leaf Jaw Positions
            DecimalString ds = new DecimalString();
            ds.Tag.Id = TagHelper.LEAF_JAW_POSITIONS;
            si.AddObject(ds);
        }
Beispiel #2
0
        private bool SetTypePointer(CodeScopeNode Scope, ref int Index, SelfVariable Self, CodeString Code)
        {
            var Plugin = Scope.GetPlugin();

            if (!Plugin.Begin())
            {
                return(false);
            }

            var Value = Plugin.NewNode(new DataPointerNode(Code, Self.TypeOfSelf));

            if (Value == null)
            {
                return(false);
            }

            var Assignment = Expressions.SetValue(Self, "_objTypePointer", Value, Plugin, Code, true);

            if (Assignment == null)
            {
                return(false);
            }

            var Command = new Command(Scope, Code, CommandType.Expression);

            Command.Expressions = new List <ExpressionNode>()
            {
                Assignment
            };
            Scope.Children.Insert(Index, Command);
            Index++;

            return(ProcessContainer(Command));
        }
Beispiel #3
0
        bool CallInitializerWithoutCmp(CodeScopeNode Scope, ref int Index, PluginRoot Plugin, ExpressionNode Size, CodeString Code)
        {
            var Self = Scope.FunctionScope.SelfVariable;

            if (!AllocateObject(Scope, ref Index, Self, Size, Plugin, Code))
            {
                return(false);
            }

            var StructuredType = Scope.StructuredScope.StructuredType;
            var ObjectType     = Identifiers.GetByFullNameFast <ClassType>(Scope.GlobalContainer, "System.Object");

            if (Identifiers.IsSubtypeOrEquivalent(StructuredType, ObjectType))
            {
                if (!SetFunctionTable(Scope, ref Index, Self, Code))
                {
                    return(false);
                }
                if (!SetTypePointer(Scope, ref Index, Self, Code))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #4
0
 bool CreateJump(CodeScopeNode Scope, int Label, CodeString Code)
 {
     Scope.FunctionScope.NeverSkippedLabels.Add(Label);
     return(CreateJump(Scope, "_" + Label, Code));
 }
Beispiel #5
0
        bool FinallyJump(CodeScopeNode Scope, Identifier JumpTo, CodeString Code)
        {
            var Plugin = Scope.GetPlugin();

            if (!Plugin.Begin())
            {
                return(false);
            }

            var Cmp_IdNode = Plugin.NewNode(new IdExpressionNode(JumpTo, Code));
            var Cmp_Null   = Plugin.NewNode(Constants.GetNullValue(Scope, Code));

            if (Cmp_IdNode == null || Cmp_Null == null)
            {
                return(false);
            }

            var Cmp_Ch   = new ExpressionNode[] { Cmp_IdNode, Cmp_Null };
            var Cmp_Node = Plugin.NewNode(new OpExpressionNode(Operator.Inequality, Cmp_Ch, Code));

            if (Cmp_Node == null || Plugin.End(ref Cmp_Node) == PluginResult.Failed)
            {
                return(false);
            }

            var Cmp_If = new Command(Scope, Code, CommandType.If);

            Cmp_If.Expressions = new List <ExpressionNode>()
            {
                Cmp_Node
            };
            Scope.Children.Add(Cmp_If);

            if (!Plugin.Begin())
            {
                return(false);
            }
            var Then_Node = Plugin.NewNode(new IdExpressionNode(JumpTo, Code));

            if (Then_Node == null || Plugin.End(ref Then_Node) == PluginResult.Failed)
            {
                return(false);
            }

            var Then_Jump = CreateJump(Cmp_If, Then_Node, Code);

            if (Then_Jump == null)
            {
                return(false);
            }

            Cmp_If.Children.Add(Then_Jump);
            if (!ProcessContainer(Then_Jump))
            {
                return(false);
            }
            if (!ProcessContainer(Cmp_If))
            {
                return(false);
            }
            return(true);
        }
Beispiel #6
0
        private static DICOMElement CreateVRObject(string vr, Constants.EncodeType encType, byte[] data, Tag t, bool isLittleEndian, bool isIndefinite)
        {
            switch (vr)
            {
                case "CS":
                    CodeString cs = new CodeString();
                    cs.ByteData = data;
                    cs.EncodeType = encType;
                    cs.IsLittleEndian = isLittleEndian;
                    cs.Tag = t;
                    return cs;

                case "SH":
                    ShortString sh = new ShortString();
                    sh.ByteData = data;
                    sh.EncodeType = encType;
                    sh.IsLittleEndian = isLittleEndian;
                    sh.Tag = t;
                    return sh;

                case "LO":
                    LongString lo = new LongString();
                    lo.ByteData = data;
                    lo.EncodeType = encType;
                    lo.IsLittleEndian = isLittleEndian;
                    lo.Tag = t;
                    return lo;

                case "ST":
                    ShortText st = new ShortText();
                    st.ByteData = data;
                    st.EncodeType = encType;
                    st.IsLittleEndian = isLittleEndian;
                    st.Tag = t;
                    return st;

                case "LT":
                    LongText lt = new LongText();
                    lt.ByteData = data;
                    lt.EncodeType = encType;
                    lt.IsLittleEndian = isLittleEndian;
                    lt.Tag = t;
                    return lt;

                case "UT":
                    UnlimitedText ut = new UnlimitedText();
                    ut.ByteData = data;
                    ut.EncodeType = encType;
                    ut.IsLittleEndian = isLittleEndian;
                    ut.Tag = t;
                    return ut;

                case "AE":
                    ApplicationEntity ae = new ApplicationEntity();
                    ae.ByteData = data;
                    ae.EncodeType = encType;
                    ae.IsLittleEndian = isLittleEndian;
                    ae.Tag = t;
                    return ae;

                case "PN":
                    PersonsName pn = new PersonsName();
                    pn.ByteData = data;
                    pn.EncodeType = encType;
                    pn.IsLittleEndian = isLittleEndian;
                    pn.Tag = t;
                    return pn;

                case "UI":
                    UniqueIdentifier ui = new UniqueIdentifier();
                    ui.ByteData = data;
                    ui.EncodeType = encType;
                    ui.IsLittleEndian = isLittleEndian;
                    ui.Tag = t;
                    return ui;

                case "DA":
                    DateVR da = new DateVR();
                    da.ByteData = data;
                    da.EncodeType = encType;
                    da.IsLittleEndian = isLittleEndian;
                    da.Tag = t;
                    return da;

                case "TM":
                    TimeVR tm = new TimeVR();
                    tm.ByteData = data;
                    tm.EncodeType = encType;
                    tm.IsLittleEndian = isLittleEndian;
                    tm.Tag = t;
                    return tm;

                case "DT":
                    DateTimeVR dt = new DateTimeVR();
                    dt.ByteData = data;
                    dt.EncodeType = encType;
                    dt.IsLittleEndian = isLittleEndian;
                    dt.Tag = t;
                    return dt;

                case "AS":
                    AgeString aSt = new AgeString();
                    aSt.ByteData = data;
                    aSt.EncodeType = encType;
                    aSt.IsLittleEndian = isLittleEndian;
                    aSt.Tag = t;
                    return aSt;

                case "IS":
                    IntegerString iSt = new IntegerString();
                    iSt.ByteData = data;
                    iSt.EncodeType = encType;
                    iSt.IsLittleEndian = isLittleEndian;
                    iSt.Tag = t;
                    return iSt;

                case "DS":
                    DecimalString ds = new DecimalString();
                    ds.ByteData = data;
                    ds.EncodeType = encType;
                    ds.IsLittleEndian = isLittleEndian;
                    ds.Tag = t;
                    return ds;

                case "SS":
                    SignedShort ss = new SignedShort();
                    ss.ByteData = data;
                    ss.EncodeType = encType;
                    ss.IsLittleEndian = isLittleEndian;
                    ss.Tag = t;
                    return ss;

                case "US":
                    UnsignedShort us = new UnsignedShort();
                    us.ByteData = data;
                    us.EncodeType = encType;
                    us.IsLittleEndian = isLittleEndian;
                    us.Tag = t;
                    return us;

                case "SL":
                    SignedLong sl = new SignedLong();
                    sl.ByteData = data;
                    sl.EncodeType = encType;
                    sl.IsLittleEndian = isLittleEndian;
                    sl.Tag = t;
                    return sl;

                case "UL":
                    UnsignedLong ul = new UnsignedLong();
                    ul.ByteData = data;
                    ul.EncodeType = encType;
                    ul.IsLittleEndian = isLittleEndian;
                    ul.Tag = t;
                    return ul;

                case "AT":
                    AttributeTag at = new AttributeTag();
                    at.ByteData = data;
                    at.EncodeType = encType;
                    at.IsLittleEndian = isLittleEndian;
                    at.Tag = t;
                    return at;

                case "FL":
                    FloatingPointSingle fl = new FloatingPointSingle();
                    fl.ByteData = data;
                    fl.EncodeType = encType;
                    fl.IsLittleEndian = isLittleEndian;
                    fl.Tag = t;
                    return fl;

                case "FD":
                    FloatingPointDouble fd = new FloatingPointDouble();
                    fd.ByteData = data;
                    fd.EncodeType = encType;
                    fd.IsLittleEndian = isLittleEndian;
                    fd.Tag = t;
                    return fd;

                case "OB":
                    if (t.Id == TagHelper.PIXEL_DATA)
                    {
                        PixelData fd1 = new PixelData(data, encType, isLittleEndian, "OB", isIndefinite);
                        fd1.Format = isIndefinite ? FrameDataFormat.ENCAPSULATED : FrameDataFormat.NATIVE;
                        fd1.EncodeType = encType;
                        fd1.IsLittleEndian = isLittleEndian;
                        fd1.Tag = t;
                        return fd1;
                    }
                    else
                    {
                        OtherByteString ob = new OtherByteString();
                        ob.ByteData = data;
                        ob.EncodeType = encType;
                        ob.IsLittleEndian = isLittleEndian;
                        ob.Tag = t;
                        return ob;
                    }
                case "OW":
                    if (t.Id == TagHelper.PIXEL_DATA)
                    {
                        PixelData fd2 = new PixelData(data, encType, isLittleEndian, "OW", isIndefinite);
                        fd2.Format = isIndefinite ? FrameDataFormat.ENCAPSULATED : FrameDataFormat.NATIVE;
                        fd2.EncodeType = encType;
                        fd2.IsLittleEndian = isLittleEndian;
                        fd2.Tag = t;
                        return fd2;
                    }
                    else
                    {
                        OtherWordString ow = new OtherWordString();
                        ow.ByteData = data;
                        ow.EncodeType = encType;
                        ow.IsLittleEndian = isLittleEndian;
                        ow.Tag = t;
                        return ow;
                    }

                case "OF":
                    OtherFloatString of = new OtherFloatString();
                    of.ByteData = data;
                    of.EncodeType = encType;
                    of.IsLittleEndian = isLittleEndian;
                    of.Tag = t;
                    return of;

                case "SQ":
                    Sequence s = new Sequence();
                    s.ByteData = data;
                    s.EncodeType = encType;
                    s.IsLittleEndian = isLittleEndian;
                    s.Tag = t;
                    s.ReadChildren();
                    return s;

                default:
                    //Case for unknown VR
                    DICOMElement dOb = new DICOMElement();
                    dOb.ByteData = data;
                    dOb.EncodeType = encType;
                    dOb.IsLittleEndian = isLittleEndian;
                    dOb.Tag = t;
                    return dOb;
            }
        }
Beispiel #7
0
        public CodeString Prettify(ICodeModule module, CodeString original)
        {
            var originalCode      = original.Code.Replace("\r", string.Empty).Split('\n');
            var originalPosition  = original.CaretPosition.StartColumn;
            var isAtLastCharacter = originalPosition == original.CaretLine.Length;

            var originalNonWhitespaceCharacters = 0;
            var isAllWhitespace = !isAtLastCharacter;

            if (!isAtLastCharacter)
            {
                for (var i = 0; i <= Math.Min(originalPosition - 1, original.CaretLine.Length - 1); i++)
                {
                    if (originalCode[original.CaretPosition.StartLine][i] != ' ')
                    {
                        originalNonWhitespaceCharacters++;
                        isAllWhitespace = false;
                    }
                }
            }

            var indent = original.CaretLine.TakeWhile(c => c == ' ').Count();

            module.DeleteLines(original.SnippetPosition.StartLine, original.SnippetPosition.LineCount);
            module.InsertLines(original.SnippetPosition.StartLine, string.Join("\r\n", originalCode));

            var prettifiedCode = module.GetLines(original.SnippetPosition)
                                 .Replace("\r", string.Empty)
                                 .Split('\n');

            var prettifiedNonWhitespaceCharacters = 0;
            var prettifiedCaretCharIndex          = 0;

            if (!isAtLastCharacter)
            {
                for (var i = 0; i < prettifiedCode[original.CaretPosition.StartLine].Length; i++)
                {
                    if (prettifiedCode[original.CaretPosition.StartLine][i] != ' ')
                    {
                        prettifiedNonWhitespaceCharacters++;
                        if (prettifiedNonWhitespaceCharacters == originalNonWhitespaceCharacters ||
                            i == prettifiedCode[original.CaretPosition.StartLine].Length - 1)
                        {
                            prettifiedCaretCharIndex = i;
                            break;
                        }
                    }
                }
            }
            else
            {
                prettifiedCaretCharIndex = prettifiedCode[original.CaretPosition.StartLine].Length;
            }

            var prettifiedPosition = new Selection(
                original.SnippetPosition.ToZeroBased().StartLine + original.CaretPosition.StartLine,
                prettifiedCode[original.CaretPosition.StartLine].Trim().Length == 0 || (isAllWhitespace && !string.IsNullOrEmpty(original.CaretLine.Substring(original.CaretPosition.StartColumn).Trim()))
                        ? Math.Min(indent, original.CaretPosition.StartColumn)
                        : Math.Min(prettifiedCode[original.CaretPosition.StartLine].Length, prettifiedCaretCharIndex + 1))
                                     .ToOneBased();

            SetSelection(module, prettifiedPosition);

            return(GetPrettifiedCodeString(original, prettifiedPosition, prettifiedCode));
        }
Beispiel #8
0
        /// <summary>
        /// Query the Information Model using the given Query Dataset.
        /// </summary>
        /// <param name="queryDataset">Query Dataset.</param>
        /// <returns>A collection of zero or more query reponse datasets.</returns>
        public override DataSetCollection QueryInformationModel(DataSet queryDataset)
        {
            DataSetCollection queryResponses = new DataSetCollection();;

            // get the query/retrieve level
            String queryRetrieveLevel = "UNKNOWN";

            DvtkData.Dimse.Attribute queryRetrieveLevelAttribute = queryDataset.GetAttribute(Tag.QUERY_RETRIEVE_LEVEL);
            if (queryRetrieveLevelAttribute != null)
            {
                CodeString codeString = (CodeString)queryRetrieveLevelAttribute.DicomValue;
                if (codeString.Values.Count == 1)
                {
                    queryRetrieveLevel = codeString.Values[0].Trim();
                }
            }

            // query at the STUDY level
            if (queryRetrieveLevel == "STUDY")
            {
                TagTypeList queryTagTypeList  = new TagTypeList();
                TagTypeList returnTagTypeList = new TagTypeList();
                foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                {
                    if (attribute.ValueRepresentation == VR.SQ)
                    {
                        foreach (SequenceItem s in ((SequenceOfItems)attribute.DicomValue).Sequence)
                        {
                            if (IsSequenceHavingValue(s))
                            {
                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                            }
                        }
                    }

                    else if ((attribute.Length != 0) &&
                             (attribute.Tag.ElementNumber != 0x0000))
                    {
                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                    }
                    if (attribute.Tag != Tag.SPECIFIC_CHARACTER_SET)
                    {
                        returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                    }
                }

                foreach (PatientStudyInformationEntity patientStudyInformationEntity in Root)
                {
                    if (patientStudyInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                    {
                        // STUDY level matches
                        DataSet queryResponse = new DataSet();

                        // if the specific character set attribute has been stored in the patient/study IE - return it in the query response
                        DvtkData.Dimse.Attribute specificCharacterSetAttribute = patientStudyInformationEntity.GetSpecificCharacterSet();
                        if (specificCharacterSetAttribute != null)
                        {
                            queryResponse.Add(specificCharacterSetAttribute);
                        }

                        patientStudyInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                        queryResponses.Add(queryResponse);
                    }
                }
            }
            else
            {
                // find the matching STUDY
                PatientStudyInformationEntity patientStudyInformationEntity = null;
                foreach (PatientStudyInformationEntity lPatientStudyInformationEntity in Root)
                {
                    if (lPatientStudyInformationEntity.IsUniqueTagFoundIn(queryDataset))
                    {
                        patientStudyInformationEntity = lPatientStudyInformationEntity;
                        break;
                    }
                }

                if (patientStudyInformationEntity != null)
                {
                    // query at the SERIES level
                    if (queryRetrieveLevel == "SERIES")
                    {
                        TagTypeList queryTagTypeList  = new TagTypeList();
                        TagTypeList returnTagTypeList = new TagTypeList();
                        foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                        {
                            // do not add higher level tags
                            if (attribute.Tag == Tag.STUDY_INSTANCE_UID)
                            {
                                continue;
                            }

                            if (attribute.ValueRepresentation == VR.SQ)
                            {
                                foreach (SequenceItem s in ((SequenceOfItems)attribute.DicomValue).Sequence)
                                {
                                    if (IsSequenceHavingValue(s))
                                    {
                                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                    }
                                }
                            }

                            else if ((attribute.Length != 0) &&
                                     (attribute.Tag.ElementNumber != 0x0000))
                            {
                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                            }
                            returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                        }

                        foreach (SeriesInformationEntity seriesInformationEntity in patientStudyInformationEntity.Children)
                        {
                            if (seriesInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                            {
                                // SERIES level matches
                                DataSet queryResponse = new DataSet();

                                // if the specific character set attribute has been stored in the series IE - return it in the query response
                                DvtkData.Dimse.Attribute specificCharacterSetAttribute = seriesInformationEntity.GetSpecificCharacterSet();
                                if (specificCharacterSetAttribute != null)
                                {
                                    queryResponse.Add(specificCharacterSetAttribute);
                                }

                                patientStudyInformationEntity.CopyUniqueTagTo(queryResponse);
                                seriesInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                queryResponses.Add(queryResponse);
                            }
                        }
                    }
                    else
                    {
                        // find the matching SERIES
                        SeriesInformationEntity seriesInformationEntity = null;
                        foreach (SeriesInformationEntity lSeriesInformationEntity in patientStudyInformationEntity.Children)
                        {
                            if (lSeriesInformationEntity.IsUniqueTagFoundIn(queryDataset))
                            {
                                seriesInformationEntity = lSeriesInformationEntity;
                                break;
                            }
                        }

                        if (seriesInformationEntity != null)
                        {
                            // query at the IMAGE level
                            if (queryRetrieveLevel == "IMAGE")
                            {
                                TagTypeList queryTagTypeList  = new TagTypeList();
                                TagTypeList returnTagTypeList = new TagTypeList();
                                foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                                {
                                    // do not add higher level tags
                                    if ((attribute.Tag == Tag.STUDY_INSTANCE_UID) ||
                                        (attribute.Tag == Tag.SERIES_INSTANCE_UID))
                                    {
                                        continue;
                                    }

                                    if (attribute.ValueRepresentation == VR.SQ)
                                    {
                                        foreach (SequenceItem s in ((SequenceOfItems)attribute.DicomValue).Sequence)
                                        {
                                            if (IsSequenceHavingValue(s))
                                            {
                                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                            }
                                        }
                                    }
                                    else if ((attribute.Length != 0) &&
                                             (attribute.Tag.ElementNumber != 0x0000))
                                    {
                                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                    }
                                    returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                                }

                                foreach (InstanceInformationEntity instanceInformationEntity in seriesInformationEntity.Children)
                                {
                                    if (instanceInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                                    {
                                        // IMAGE level matches
                                        DataSet queryResponse = new DataSet();

                                        // if the specific character set attribute has been stored in the instance IE - return it in the query response
                                        DvtkData.Dimse.Attribute specificCharacterSetAttribute = instanceInformationEntity.GetSpecificCharacterSet();
                                        if (specificCharacterSetAttribute != null)
                                        {
                                            queryResponse.Add(specificCharacterSetAttribute);
                                        }

                                        patientStudyInformationEntity.CopyUniqueTagTo(queryResponse);
                                        seriesInformationEntity.CopyUniqueTagTo(queryResponse);
                                        instanceInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                        queryResponses.Add(queryResponse);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(queryResponses);
        }
Beispiel #9
0
        public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List <Modifier> Out)
        {
            var Result = Code.StartsWith(Strings, null, new IdCharCheck(true));

            if (Result.Index != -1)
            {
                var State   = Container.State;
                var ModCode = Code.Substring(0, Result.String.Length);

                IdentifierAccess Access;
                if (Result.Index == 0)
                {
                    Access = IdentifierAccess.Public;
                }
                else if (Result.Index == 1)
                {
                    Access = IdentifierAccess.Protected;
                }
                else if (Result.Index == 2)
                {
                    Access = IdentifierAccess.Private;
                }
                else if (Result.Index == 3)
                {
                    Access = IdentifierAccess.Internal;
                }
                else
                {
                    throw new NotImplementedException();
                }

                for (var i = 0; i < Out.Count; i++)
                {
                    var AccessMod = Out[i] as AccessModifier;
                    if (AccessMod != null)
                    {
                        var Allowed = false;
                        if (Access == IdentifierAccess.Internal)
                        {
                            Allowed = AccessMod.Access == IdentifierAccess.Protected;
                        }
                        else if (Access == IdentifierAccess.Protected)
                        {
                            Allowed = AccessMod.Access == IdentifierAccess.Internal;
                        }

                        if (!Allowed)
                        {
                            State.Messages.Add(MessageId.NotExpected, ModCode);
                            return(SimpleRecResult.Failed);
                        }
                    }
                }

                Out.Add(new AccessModifier(ModCode, Access));
                Code = Code.Substring(Result.String.Length).Trim();
                return(SimpleRecResult.Succeeded);
            }

            return(SimpleRecResult.Unknown);
        }
        public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settings, out CodeString result)
        {
            result = null;
            if (!_scpInputLookup.TryGetValue(e.Character, out var pair) && e.Character != '\b')
            {
                return(false);
            }

            var original = CodePaneHandler.GetCurrentLogicalLine(e.Module);

            if (original == null || original.Lines.Length == MaximumLines)
            {
                // selection spans more than a single logical line, or
                // logical line somehow spans more than the maximum number of physical lines in a logical line of code (25).
                return(false);
            }

            if (pair != null)
            {
                if (!HandleInternal(e, original, pair, out result))
                {
                    return(false);
                }
            }
            else if (e.Character == '\b')
            {
                foreach (var scp in _selfClosingPairs)
                {
                    if (HandleInternal(e, original, scp, out result))
                    {
                        break;
                    }
                }
            }

            if (result == null)
            {
                return(false);
            }

            var snippetPosition = new Selection(result.SnippetPosition.StartLine, 1, result.SnippetPosition.EndLine, 1);

            result = new CodeString(result.Code, result.CaretPosition, snippetPosition);

            e.Handled = true;
            return(true);
        }
Beispiel #11
0
        public static byte[] GetStringBytes(VR vr, IDICOMElement el)
        {
            string data;

            byte[] unpadded;
            switch (vr)
            {
            case VR.AgeString:
                AgeString age = el as AgeString;
                data     = age.DataContainer.SingleValue;
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.ApplicationEntity:
                ApplicationEntity ae = el as ApplicationEntity;
                unpadded = GetASCIIBytes(ae.DataContainer.SingleValue);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.CodeString:
                CodeString cs = el as CodeString;
                unpadded = GetASCIIBytes(cs.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.Date:
                Date d = el as Date;
                data     = StringDataComposer.ComposeDate(d.Data);
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.DateTime:
                EvilDICOM.Core.Element.DateTime dt = el as EvilDICOM.Core.Element.DateTime;
                data     = StringDataComposer.ComposeDateTime(dt.DataContainer.SingleValue);
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.DecimalString:
                DecimalString ds = el as DecimalString;
                data     = StringDataComposer.ComposeDecimalString(ds.DataContainer.MultipicityValue.ToArray());
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.IntegerString:
                IntegerString iSt = el as IntegerString;
                data     = StringDataComposer.ComposeIntegerString(iSt.DataContainer.MultipicityValue.ToArray());
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.LongString:
                LongString ls = el as LongString;
                unpadded = GetASCIIBytes(ls.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.LongText:
                LongText lt = el as LongText;
                unpadded = GetASCIIBytes(lt.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.PersonName:
                PersonName pn = el as PersonName;
                unpadded = GetASCIIBytes(pn.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.ShortString:
                ShortString ss = el as ShortString;
                unpadded = GetASCIIBytes(ss.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.ShortText:
                ShortText st = el as ShortText;
                unpadded = GetASCIIBytes(st.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.Time:
                Time t = el as Time;
                data     = StringDataComposer.ComposeTime(t.DataContainer.SingleValue);
                unpadded = GetASCIIBytes(data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.UnlimitedText:
                UnlimitedText ut = el as UnlimitedText;
                unpadded = GetASCIIBytes(ut.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            case VR.UniqueIdentifier:
                UniqueIdentifier ui = el as UniqueIdentifier;
                unpadded = GetASCIIBytes(ui.Data);
                return(DataRestriction.EnforceEvenLength(unpadded, vr));

            default: return(null);
            }
        }
Beispiel #12
0
        public ExprRecResult Recognize(CodeString Code, CodeString Function, CodeString[] Params,
                                       CodeString[] GenericParams, PluginRoot Plugin, ref ExpressionNode Out)
        {
            var State = Plugin.State;

            if (Function.IsEqual("id_desc_ptr"))
            {
                if (GenericParams != null && GenericParams.Length != 0)
                {
                    State.Messages.Add(MessageId.NonGenericIdentifier, Function);
                    return(ExprRecResult.Failed);
                }

                if (Params.Length != 1)
                {
                    State.Messages.Add(MessageId.ParamCount, Code);
                    return(ExprRecResult.Failed);
                }

                var Container = Plugin.Container;
                var Id        = Container.RecognizeIdentifier(Params[0]);
                if (Id == null)
                {
                    return(ExprRecResult.Failed);
                }

                Out = new DataPointerNode(Code, Id);
                return(ExprRecResult.Succeeded);
            }

            if (Function.IsEqual("assembly_desc_ptr"))
            {
                var Global = Plugin.Container.GlobalContainer;
                if (GenericParams != null && GenericParams.Length != 0)
                {
                    State.Messages.Add(MessageId.NonGenericIdentifier, Function);
                    return(ExprRecResult.Failed);
                }

                if (Params.Length == 0)
                {
                    Out = new DataPointerNode(Code, Global.OutputAssembly);
                    return(ExprRecResult.Succeeded);
                }
                else
                {
                    if (Params.Length != 1)
                    {
                        State.Messages.Add(MessageId.ParamCount, Code);
                        return(ExprRecResult.Failed);
                    }

                    string String;
                    if (!Constants.RecognizeString(Params[0], Plugin, out String))
                    {
                        return(ExprRecResult.Failed);
                    }

                    var Assembly = Global.GetAssembly(String);
                    if (Assembly == null)
                    {
                        State.Messages.Add(MessageId.UnknownId, Params[0]);
                        return(ExprRecResult.Failed);
                    }

                    Out = new DataPointerNode(Code, Assembly);
                    return(ExprRecResult.Succeeded);
                }
            }

            return(ExprRecResult.Unknown);
        }
Beispiel #13
0
        public ExprRecResult Recognize(CodeString Code, PluginRoot Plugin, ref ExpressionNode Ret)
        {
            if (Code.Length == 0)
            {
                return(ExprRecResult.Unknown);
            }

            var OldCode   = Code;
            var State     = Plugin.State;
            var Container = Plugin.Container;
            var Global    = Container.GlobalContainer;

            var RadixSpecified = false;
            var Radix          = 10;

            var Sign = RecognizerHelper.GetSign(ref Code);

            if (Code.Length == 0)
            {
                return(ExprRecResult.Unknown);
            }

            if (AtStartStrings != null)
            {
                var Result = Code.StartsWith(AtStartStrings, Skip);
                if (Result.Index != -1)
                {
                    Code = Code.TrimmedSubstring(State, Result.String.Length);
                    if (!Code.IsValid)
                    {
                        return(ExprRecResult.Failed);
                    }

                    RadixSpecified = true;
                    Radix          = AtStart[Result.Index].Radix;
                }
            }

            if (AtEndStrings != null)
            {
                var Result = Code.EndsWith(AtEndStrings, Skip);
                if (Result.Index != -1)
                {
                    if (Radix != -1)
                    {
                        State.Messages.Add(MessageId.MultipleRadix, Code);
                        return(ExprRecResult.Failed);
                    }

                    Code = Code.TrimmedSubstring(State, Result.String.Length);
                    if (!Code.IsValid)
                    {
                        return(ExprRecResult.Failed);
                    }

                    RadixSpecified = true;
                    Radix          = AtStart[Result.Index].Radix;
                }
            }

            if (RecognizerHelper.GetSign(ref Code))
            {
                Sign = !Sign;
            }
            if (Code.Length == 0 || (!char.IsDigit(Code[0]) && !RadixSpecified))
            {
                return(ExprRecResult.Unknown);
            }

            var Options = new ConvStrToNumberOptions();
            var Type    = TypeExtractor(Container, ref Code);

            if (Type == null)
            {
                Options.Type = ConstValueType.Unknown;
            }
            else
            {
                var RType = Type.RealId as Type;
                Options.Type = RType.ConstValueType;
            }

            Code = Code.Trim();
            if (Code.Length == 0)
            {
                return(ExprRecResult.Unknown);
            }

            Options.Radix           = Radix;
            Options.Number          = Code.String;
            Options.LetterCase      = LetterCase.OnlyUpper;
            Options.EnableENotation = true;
            Options.Sign            = Sign;

            ConstValue Value;
            var        Res = RecognizerHelper.ConvStrToNumber(State, Code, Options, out Value);

            if (Res == SimpleRecResult.Unknown)
            {
                return(ExprRecResult.Unknown);
            }
            else if (Res == SimpleRecResult.Failed)
            {
                return(ExprRecResult.Failed);
            }

            if (Type == null)
            {
                Type = Constants.GetDefaultType(Container, Value.Type);
                if (Type.RealId is NumberType && !Value.CheckBounds(Type))
                {
                    var SystemType = Type.GetType();

                    do
                    {
                        var RType = Type.RealId as Type;
                        Type = Global.CommonIds.GetIdentifier(SystemType, RType.Size * 2);

                        if (Type == null)
                        {
                            if (typeof(SignedType).IsEquivalentTo(SystemType))
                            {
                                Type = Global.CommonIds.GetLargestType(typeof(UnsignedType));
                            }
                            else
                            {
                                Type = Global.CommonIds.GetLargestType(typeof(SignedType));
                            }
                            break;
                        }
                    } while (!Value.CheckBounds(Type));
                }
            }

            if (!Value.CheckBounds(State, Type, OldCode))
            {
                return(ExprRecResult.Failed);
            }

            var Flags = Options.Type == ConstValueType.Unknown ?
                        ExpressionFlags.AutoConvert : ExpressionFlags.None;

            Ret = new ConstExpressionNode(Type, Value, OldCode, Flags);
            return(ExprRecResult.Succeeded);
        }
Beispiel #14
0
        /// <summary>
        /// Retrieve a list of filenames from the Information Model. The filenames match the
        /// individual instances matching the retrieve dataset attributes.
        /// </summary>
        /// <param name="retrieveDataset">Retrive dataset.</param>
        /// <returns>File list - containing the filenames of all instances matching the retrieve dataset attributes.</returns>
        public DvtkData.Collections.StringCollection RetrieveInformationModel(DataSet retrieveDataset)
        {
            DvtkData.Collections.StringCollection fileList = new DvtkData.Collections.StringCollection();

            // get the query/retrieve level
            String queryRetrieveLevel = "UNKNOWN";

            DvtkData.Dimse.Attribute queryRetrieveLevelAttribute = retrieveDataset.GetAttribute(Tag.QUERY_RETRIEVE_LEVEL);
            if (queryRetrieveLevelAttribute != null)
            {
                CodeString codeString = (CodeString)queryRetrieveLevelAttribute.DicomValue;
                if (codeString.Values.Count == 1)
                {
                    queryRetrieveLevel = codeString.Values[0].Trim();
                }
            }

            // find the matching PATIENT
            PatientInformationEntity patientInformationEntity = null;

            foreach (PatientInformationEntity lPatientInformationEntity in Root)
            {
                if (lPatientInformationEntity.IsUniqueTagFoundIn(retrieveDataset))
                {
                    patientInformationEntity = lPatientInformationEntity;
                    break;
                }
            }

            if (patientInformationEntity != null)
            {
                // retrieve at the PATIENT level
                if (queryRetrieveLevel == "PATIENT")
                {
                    foreach (StudyInformationEntity studyInformationEntity in patientInformationEntity.Children)
                    {
                        foreach (SeriesInformationEntity seriesInformationEntity in studyInformationEntity.Children)
                        {
                            foreach (InstanceInformationEntity instanceInformationEntity in seriesInformationEntity.Children)
                            {
                                fileList.Add(instanceInformationEntity.Filename);
                            }
                        }
                    }
                }
                else
                {
                    // find the matching STUDY
                    StudyInformationEntity studyInformationEntity = null;
                    foreach (StudyInformationEntity lStudyInformationEntity in patientInformationEntity.Children)
                    {
                        if (lStudyInformationEntity.IsUniqueTagFoundIn(retrieveDataset))
                        {
                            studyInformationEntity = lStudyInformationEntity;
                            break;
                        }
                    }

                    if (studyInformationEntity != null)
                    {
                        // retrieve at the STUDY level
                        if (queryRetrieveLevel == "STUDY")
                        {
                            foreach (SeriesInformationEntity seriesInformationEntity in studyInformationEntity.Children)
                            {
                                foreach (InstanceInformationEntity instanceInformationEntity in seriesInformationEntity.Children)
                                {
                                    fileList.Add(instanceInformationEntity.Filename);
                                }
                            }
                        }
                        else
                        {
                            // find the matching SERIES
                            SeriesInformationEntity seriesInformationEntity = null;
                            foreach (SeriesInformationEntity lSeriesInformationEntity in studyInformationEntity.Children)
                            {
                                if (lSeriesInformationEntity.IsUniqueTagFoundIn(retrieveDataset))
                                {
                                    seriesInformationEntity = lSeriesInformationEntity;
                                    break;
                                }
                            }
                            if (seriesInformationEntity != null)
                            {
                                // retrieve at the SERIES level
                                if (queryRetrieveLevel == "SERIES")
                                {
                                    foreach (InstanceInformationEntity instanceInformationEntity in seriesInformationEntity.Children)
                                    {
                                        fileList.Add(instanceInformationEntity.Filename);
                                    }
                                }
                                else
                                {
                                    // find the matching IMAGE
                                    InstanceInformationEntity instanceInformationEntity = null;
                                    foreach (InstanceInformationEntity lInstanceInformationEntity in seriesInformationEntity.Children)
                                    {
                                        if (lInstanceInformationEntity.IsUniqueTagFoundIn(retrieveDataset))
                                        {
                                            instanceInformationEntity = lInstanceInformationEntity;
                                            break;
                                        }
                                    }

                                    // retrieve at the IMAGE level
                                    if ((instanceInformationEntity != null) &&
                                        (queryRetrieveLevel == "IMAGE"))
                                    {
                                        fileList.Add(instanceInformationEntity.Filename);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(fileList);
        }
Beispiel #15
0
 public SelfClosingPairTestInfo(CodeString original, char input)
     : this(new Mock <SelfClosingPairCompletionService>(), original, original, input, original)
 {
 }
Beispiel #16
0
        /// <summary>
        /// Query the Information Model using the given Query Dataset.
        /// </summary>
        /// <param name="queryDataset">Query Dataset.</param>
        /// <returns>A collection of zero or more query reponse datasets.</returns>
        public override DataSetCollection QueryInformationModel(DataSet queryDataset)
        {
            DataSetCollection queryResponses = new DataSetCollection();

            // get the query/retrieve level
            String queryRetrieveLevel = "UNKNOWN";

            DvtkData.Dimse.Attribute queryRetrieveLevelAttribute = queryDataset.GetAttribute(Tag.QUERY_RETRIEVE_LEVEL);
            if (queryRetrieveLevelAttribute != null)
            {
                CodeString codeString = (CodeString)queryRetrieveLevelAttribute.DicomValue;
                if (codeString.Values.Count == 1)
                {
                    queryRetrieveLevel = codeString.Values[0].Trim();
                }
            }

            // query at the PATIENT level
            if (queryRetrieveLevel == "PATIENT")
            {
                TagTypeList queryTagTypeList  = new TagTypeList();
                TagTypeList returnTagTypeList = new TagTypeList();
                foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                {
                    if (attribute.Length != 0)
                    {
                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                    }
                    returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                }

                foreach (PatientInformationEntity patientInformationEntity in Root)
                {
                    if (patientInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                    {
                        // PATIENT level matches
                        DataSet queryResponse = new DataSet();
                        patientInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                        patientInformationEntity.CopyAdditionalAttributes(queryResponse);
                        queryResponses.Add(queryResponse);
                    }
                }
            }
            else
            {
                // find the matching PATIENT
                PatientInformationEntity patientInformationEntity = null;
                foreach (PatientInformationEntity lPatientInformationEntity in Root)
                {
                    if (lPatientInformationEntity.IsUniqueTagFoundIn(queryDataset))
                    {
                        patientInformationEntity = lPatientInformationEntity;
                        break;
                    }
                }
                if (patientInformationEntity != null)
                {
                    // query at the STUDY level
                    if (queryRetrieveLevel == "STUDY")
                    {
                        TagTypeList queryTagTypeList  = new TagTypeList();
                        TagTypeList returnTagTypeList = new TagTypeList();
                        foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                        {
                            // do not add higher level tag
                            if (attribute.Tag == Tag.PATIENT_ID)
                            {
                                continue;
                            }

                            if (attribute.Length != 0)
                            {
                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                            }
                            returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                        }

                        foreach (StudyInformationEntity studyInformationEntity in patientInformationEntity.Children)
                        {
                            if (studyInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                            {
                                // STUDY level matches
                                DataSet queryResponse = new DataSet();
                                patientInformationEntity.CopyUniqueTagTo(queryResponse);
                                studyInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                studyInformationEntity.CopyAdditionalAttributes(queryResponse);
                                queryResponses.Add(queryResponse);
                            }
                        }
                    }
                    else
                    {
                        // find the matching STUDY
                        StudyInformationEntity studyInformationEntity = null;
                        foreach (StudyInformationEntity lStudyInformationEntity in patientInformationEntity.Children)
                        {
                            if (lStudyInformationEntity.IsUniqueTagFoundIn(queryDataset))
                            {
                                studyInformationEntity = lStudyInformationEntity;
                                break;
                            }
                        }

                        if (studyInformationEntity != null)
                        {
                            // query at the SERIES level
                            if (queryRetrieveLevel == "SERIES")
                            {
                                TagTypeList queryTagTypeList  = new TagTypeList();
                                TagTypeList returnTagTypeList = new TagTypeList();
                                foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                                {
                                    // do not add higher level tags
                                    if ((attribute.Tag == Tag.PATIENT_ID) ||
                                        (attribute.Tag == Tag.STUDY_INSTANCE_UID))
                                    {
                                        continue;
                                    }

                                    if (attribute.Length != 0)
                                    {
                                        queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                    }
                                    returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                                }

                                foreach (SeriesInformationEntity seriesInformationEntity in studyInformationEntity.Children)
                                {
                                    if (seriesInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                                    {
                                        // SERIES level matches
                                        DataSet queryResponse = new DataSet();
                                        patientInformationEntity.CopyUniqueTagTo(queryResponse);
                                        studyInformationEntity.CopyUniqueTagTo(queryResponse);
                                        seriesInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                        seriesInformationEntity.CopyAdditionalAttributes(queryResponse);
                                        queryResponses.Add(queryResponse);
                                    }
                                }
                            }
                            else
                            {
                                // find the matching SERIES
                                SeriesInformationEntity seriesInformationEntity = null;
                                foreach (SeriesInformationEntity lSeriesInformationEntity in studyInformationEntity.Children)
                                {
                                    if (lSeriesInformationEntity.IsUniqueTagFoundIn(queryDataset))
                                    {
                                        seriesInformationEntity = lSeriesInformationEntity;
                                        break;
                                    }
                                }

                                if (seriesInformationEntity != null)
                                {
                                    // query at the IMAGE level
                                    if (queryRetrieveLevel == "IMAGE")
                                    {
                                        TagTypeList queryTagTypeList  = new TagTypeList();
                                        TagTypeList returnTagTypeList = new TagTypeList();
                                        foreach (DvtkData.Dimse.Attribute attribute in queryDataset)
                                        {
                                            // do not add higher level tags
                                            if ((attribute.Tag == Tag.PATIENT_ID) ||
                                                (attribute.Tag == Tag.STUDY_INSTANCE_UID) ||
                                                (attribute.Tag == Tag.SERIES_INSTANCE_UID))
                                            {
                                                continue;
                                            }

                                            if (attribute.Length != 0)
                                            {
                                                queryTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagRequired));
                                            }
                                            returnTagTypeList.Add(new TagType(attribute.Tag, TagTypeEnum.TagOptional));
                                        }

                                        foreach (InstanceInformationEntity instanceInformationEntity in seriesInformationEntity.Children)
                                        {
                                            if (instanceInformationEntity.IsFoundIn(queryTagTypeList, queryDataset))
                                            {
                                                // IMAGE level matches
                                                DataSet queryResponse = new DataSet();
                                                patientInformationEntity.CopyUniqueTagTo(queryResponse);
                                                studyInformationEntity.CopyUniqueTagTo(queryResponse);
                                                seriesInformationEntity.CopyUniqueTagTo(queryResponse);
                                                instanceInformationEntity.CopyTo(returnTagTypeList, queryResponse);
                                                instanceInformationEntity.CopyAdditionalAttributes(queryResponse);
                                                queryResponses.Add(queryResponse);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(queryResponses);
        }
Beispiel #17
0
        public SimpleRecResult Recognize(IdContainer Container, ref CodeString Code, List <Modifier> Out)
        {
            var Result = Code.StartsWith(Strings, null, new IdCharCheck(true));

            if (Result.Index != -1)
            {
                var State   = Container.State;
                var ModCode = Code.Substring(0, Result.String.Length);

                IdentifierFlags Flags;
                if (Result.Index == 0)
                {
                    Flags = IdentifierFlags.Virtual;
                }
                else if (Result.Index == 1)
                {
                    Flags = IdentifierFlags.Override;
                }
                else if (Result.Index == 2)
                {
                    Flags = IdentifierFlags.Abstract;
                }
                else if (Result.Index == 3)
                {
                    Flags = IdentifierFlags.Sealed;
                }
                else if (Result.Index == 4)
                {
                    Flags = IdentifierFlags.Static;
                }
                else if (Result.Index == 5)
                {
                    Flags = IdentifierFlags.Extern;
                }
                else if (Result.Index == 6)
                {
                    Flags = IdentifierFlags.ReadOnly;
                }
                else if (Result.Index == 7)
                {
                    Flags = IdentifierFlags.HideBaseId;
                }
                else
                {
                    throw new NotImplementedException();
                }

                for (var i = 0; i < Out.Count; i++)
                {
                    var FlagMod = Out[i] as FlagModifier;
                    if (FlagMod != null && (FlagMod.Flags & Flags) != 0)
                    {
                        State.Messages.Add(MessageId.NotExpected, ModCode);
                        return(SimpleRecResult.Failed);
                    }
                }

                Out.Add(new FlagModifier(ModCode, Flags));
                Code = Code.Substring(Result.String.Length).Trim();
                return(SimpleRecResult.Succeeded);
            }

            return(SimpleRecResult.Unknown);
        }
Beispiel #18
0
        /// <summary>
        /// Retrieve a list of filenames from the Information Model. The filenames match the
        /// individual instances matching the retrieve dataset attributes.
        /// </summary>
        /// <param name="retrieveDataset">Retrive dataset.</param>
        /// <returns>File list - containing the filenames of all instances matching the retrieve dataset attributes.</returns>
        public DvtkData.Collections.StringCollection RetrieveInformationModel(DataSet retrieveDataset)
        {
            DvtkData.Collections.StringCollection fileList = new DvtkData.Collections.StringCollection();

            // get the query/retrieve level
            String queryRetrieveLevel = "UNKNOWN";

            DvtkData.Dimse.Attribute queryRetrieveLevelAttribute = retrieveDataset.GetAttribute(Tag.QUERY_RETRIEVE_LEVEL);
            if (queryRetrieveLevelAttribute != null)
            {
                CodeString codeString = (CodeString)queryRetrieveLevelAttribute.DicomValue;
                if (codeString.Values.Count == 1)
                {
                    queryRetrieveLevel = codeString.Values[0].Trim();
                }
            }

            // find the matching STUDY
            BaseInformationEntityList patientStudyInformationEntities = new BaseInformationEntityList();

            foreach (PatientStudyInformationEntity lPatientStudyInformationEntity in Root)
            {
                if (lPatientStudyInformationEntity.IsUniqueTagFoundIn(retrieveDataset))
                {
                    patientStudyInformationEntities.Add(lPatientStudyInformationEntity);
                }
            }

            if (patientStudyInformationEntities.Count > 0)
            {
                // retrieve at the STUDY level
                if (queryRetrieveLevel == "STUDY")
                {
                    foreach (PatientStudyInformationEntity patientStudyInformationEntity in patientStudyInformationEntities)
                    {
                        foreach (String fileName in patientStudyInformationEntity.FileNames)
                        {
                            fileList.Add(fileName);
                        }
                    }
                }
                else
                {
                    // find the matching SERIES
                    BaseInformationEntityList seriesInformationEntities = patientStudyInformationEntities[0].ChildrenWithUniqueTagFoundIn(retrieveDataset);

                    if (seriesInformationEntities.Count > 0)
                    {
                        // retrieve at the SERIES level
                        if (queryRetrieveLevel == "SERIES")
                        {
                            foreach (SeriesInformationEntity seriesInformationEntity in seriesInformationEntities)
                            {
                                foreach (String fileName in seriesInformationEntity.FileNames)
                                {
                                    fileList.Add(fileName);
                                }
                            }
                        }
                        else
                        {
                            // find the matching IMAGE
                            BaseInformationEntityList instanceInformationEntities = seriesInformationEntities[0].ChildrenWithUniqueTagFoundIn(retrieveDataset);

                            // retrieve at the IMAGE level
                            if ((instanceInformationEntities.Count > 0) &&
                                (queryRetrieveLevel == "IMAGE"))
                            {
                                foreach (InstanceInformationEntity instanceInformationEntity in instanceInformationEntities)
                                {
                                    fileList.Add(instanceInformationEntity.Filename);
                                }
                            }
                        }
                    }
                }
            }

            return(fileList);
        }
Beispiel #19
0
        public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Out)
        {
            var State  = Container.State;
            var Result = RecognizerHelper.Find(this, State, Code.String);

            if (Result.Position != -1)
            {
                var OldCode = Code;
                var Mods    = Modifiers.Recognize(Container, ref Code);
                if (Mods == null)
                {
                    return(SimpleRecResult.Failed);
                }

                Result.Position -= Code.Index - OldCode.Index;

                var Left = Code.TrimmedSubstring(State, 0, Result.Position, Options.EnableMessages);
                if (!Left.IsValid)
                {
                    return(SimpleRecResult.Failed);
                }

                var Right = Code.TrimmedSubstring(State, Result.Position + Result.String.Length, Options.EnableMessages);
                if (!Right.IsValid)
                {
                    return(SimpleRecResult.Failed);
                }

                var Flags = VarDeclarationListFlags.EnableUnnamed | VarDeclarationListFlags.EnableInitValue
                            | VarDeclarationListFlags.EnableVoidOnly;

                if (Options.EnableMessages)
                {
                    Flags |= VarDeclarationListFlags.EnableMessages;
                }
                var ParamDeclList = VarDeclarationList.Create(Container, Left, null, Flags);
                if (ParamDeclList == null)
                {
                    return(SimpleRecResult.Failed);
                }

                if (ParamDeclList.Count == 1 && ParamDeclList[0].Type.RealId is VoidType)
                {
                    ParamDeclList.RemoveAt(0);
                }

                var Params = ParamDeclList.ToFuncParams(Container.GetPlugin());
                if (Params == null || Params.Contains(null))
                {
                    return(SimpleRecResult.Failed);
                }

                Flags &= ~VarDeclarationListFlags.EnableInitValue;
                var RetDeclList = VarDeclarationList.Create(Container, Right, null, Flags);
                if (RetDeclList == null)
                {
                    return(SimpleRecResult.Failed);
                }

                Identifier RetType;
                if (RetDeclList.Count == 1 && !RetDeclList[0].Name.IsValid)
                {
                    RetType = RetDeclList[0].Type;
                }
                else
                {
                    RetType = RetDeclList.ToTupleType(Container, Options.EnableMessages);
                    if (RetType == null)
                    {
                        return(SimpleRecResult.Failed);
                    }
                }

                var CallConv  = Container.DefaultCallConv;
                var Succeeded = true;
                var Static    = false;

                Mods.ForEach(x =>
                {
                    if (x is CallingConventionModifier)
                    {
                        var CCM  = x as CallingConventionModifier;
                        CallConv = CCM.CallingConvention;
                    }
                    else if (x is FlagModifier)
                    {
                        var FM = x as FlagModifier;
                        if ((FM.Flags & IdentifierFlags.Static) != 0)
                        {
                            Static = true;
                        }

                        if ((FM.Flags & ~IdentifierFlags.Static) != 0)
                        {
                            if (Options.EnableMessages)
                            {
                                State.Messages.Add(MessageId.ModifierCantBeUsed, x.Code);
                            }

                            Succeeded = false;
                        }
                    }
                    else
                    {
                        if (Options.EnableMessages)
                        {
                            State.Messages.Add(MessageId.ModifierCantBeUsed, x.Code);
                        }

                        Succeeded = false;
                    }
                });

                if (!Succeeded)
                {
                    return(SimpleRecResult.Failed);
                }

                Identifier FuncType = new TypeOfFunction(Container, CallConv, RetType, Params);
                Out = Static ? FuncType : new NonstaticFunctionType(Container, FuncType);

                if (Options.Func == null || Options.Func(Out))
                {
                    return(SimpleRecResult.Succeeded);
                }
                return(SimpleRecResult.Succeeded);
            }

            return(SimpleRecResult.Unknown);
        }
Beispiel #20
0
 public SelfClosingPairTestInfo(CodeString original, CodeString prettified, char input, CodeString rePrettified)
     : this(new Mock <SelfClosingPairCompletionService>(), original, prettified, input, rePrettified)
 {
 }
Beispiel #21
0
        public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Ret)
        {
            if (Code.StartsWith(Operators, Skip, IdCharCheck: new IdCharCheck(true)).Index == 0)
            {
                var State = Container.State;
                if (Code[Code.Length - 1] != ')')
                {
                    if (Options.EnableMessages)
                    {
                        State.Messages.Add(MessageId.NotExpected, Code);
                    }

                    return(SimpleRecResult.Failed);
                }

                var BracketPos = Code.GetBracketPos(State, true, Options.EnableMessages);
                if (BracketPos == -1)
                {
                    return(SimpleRecResult.Failed);
                }

                var Left = Code.TrimmedSubstring(State, 3, BracketPos - 3, Options.EnableMessages);
                if (!Left.IsValid)
                {
                    return(SimpleRecResult.Failed);
                }

                CallingConvention CallConv;
                if (!Modifiers.GetCallConv(Container, ref Left, out CallConv))
                {
                    return(SimpleRecResult.Failed);
                }

                if (CallConv == CallingConvention.Unknown)
                {
                    CallConv = Container.DefaultCallConv;
                }

                var TOptions = Options;
                TOptions.Func = x => x.RealId is Type;

                var RetType   = Identifiers.Recognize(Container, Left, TOptions);
                var StrParams = Code.Substring(BracketPos + 1, Code.Length - BracketPos - 2).Trim();

                var Flags = VarDeclarationListFlags.EnableUnnamed | VarDeclarationListFlags.EnableInitValue;
                if (Options.EnableMessages)
                {
                    Flags |= VarDeclarationListFlags.EnableMessages;
                }
                var DeclList = VarDeclarationList.Create(Container, StrParams, null, Flags);
                if (DeclList == null || RetType == null)
                {
                    return(SimpleRecResult.Failed);
                }

                if (!(RetType.RealId is Type))
                {
                    State.Messages.Add(MessageId.UnknownType, Left);
                    return(SimpleRecResult.Failed);
                }

                var Params = DeclList.ToFuncParams(Container.GetPlugin());
                if (Params == null || Params.Contains(null))
                {
                    return(SimpleRecResult.Failed);
                }

                Ret = new TypeOfFunction(Container, CallConv, RetType, Params);
                if (Options.Func == null || Options.Func(Ret))
                {
                    return(SimpleRecResult.Succeeded);
                }
            }

            return(SimpleRecResult.Unknown);
        }
Beispiel #22
0
        private System.String GetAttributeValue(DvtkData.Dimse.Attribute attribute)
        {
            System.String attributeValue = System.String.Empty;
            if ((attribute == null) ||
                (attribute.Length == 0))
            {
                return(attributeValue);
            }

            switch (attribute.ValueRepresentation)
            {
            case VR.AE:
            {
                ApplicationEntity applicationEntity = (ApplicationEntity)attribute.DicomValue;
                attributeValue = applicationEntity.Values[0];
                break;
            }

            case VR.AS:
            {
                AgeString ageString = (AgeString)attribute.DicomValue;
                attributeValue = ageString.Values[0];
                break;
            }

            case VR.CS:
            {
                CodeString codeString = (CodeString)attribute.DicomValue;
                attributeValue = codeString.Values[0];
                break;
            }

            case VR.DA:
            {
                Date date = (Date)attribute.DicomValue;
                attributeValue = date.Values[0];
                break;
            }

            case VR.DS:
            {
                DecimalString decimalString = (DecimalString)attribute.DicomValue;
                attributeValue = decimalString.Values[0];
                break;
            }

            case VR.DT:
            {
                DvtkData.Dimse.DateTime dateTime = (DvtkData.Dimse.DateTime)attribute.DicomValue;
                attributeValue = dateTime.Values[0];
                break;
            }

            case VR.IS:
            {
                IntegerString integerString = (IntegerString)attribute.DicomValue;
                attributeValue = integerString.Values[0];
                break;
            }

            case VR.LO:
            {
                LongString longString = (LongString)attribute.DicomValue;
                attributeValue = longString.Values[0];
                break;
            }

            case VR.LT:
            {
                LongText longText = (LongText)attribute.DicomValue;
                attributeValue = longText.Value;
                break;
            }

            case VR.PN:
            {
                PersonName personName = (PersonName)attribute.DicomValue;
                attributeValue = personName.Values[0];
                break;
            }

            case VR.SH:
            {
                ShortString shortString = (ShortString)attribute.DicomValue;
                attributeValue = shortString.Values[0];
                break;
            }

            case VR.SQ:
            {
                // Special case looking for the SOP Class UID
                SequenceOfItems sequenceOfItems = (SequenceOfItems)attribute.DicomValue;
                if ((sequenceOfItems != null) &&
                    (sequenceOfItems.Sequence.Count == 1))
                {
                    // Special case looking for the SOP Class UID
                    SequenceItem item = sequenceOfItems.Sequence[0];
                    attribute      = item.GetAttribute(new Tag(0x0008, 0x1150));
                    attributeValue = GetAttributeValue(attribute);
                }
                break;
            }

            case VR.ST:
            {
                ShortText shortText = (ShortText)attribute.DicomValue;
                attributeValue = shortText.Value;
                break;
            }

            case VR.TM:
            {
                Time time = (Time)attribute.DicomValue;
                attributeValue = time.Values[0];
                break;
            }

            case VR.UI:
            {
                UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                attributeValue = uniqueIdentifier.Values[0];
                break;
            }

            default:
                break;
            }

            return(attributeValue);
        }
Beispiel #23
0
        public SimpleRecResult Recognize(IdContainer Container, CodeString Code, GetIdOptions Options, ref Identifier Ret)
        {
            var Position = Code.Length - 1;

            if (Position >= 0 && Code[Position] == ']')
            {
                var State = Container.State;
                var ZPos  = Code.GetBracketPos(State, true, Options.EnableMessages);
                if (ZPos == -1)
                {
                    return(SimpleRecResult.Failed);
                }

                var Left = Code.TrimmedSubstring(State, 0, ZPos, Options.EnableMessages);
                if (!Left.IsValid)
                {
                    return(SimpleRecResult.Failed);
                }

                var TOptions = Options;
                TOptions.Func = x => x.RealId is Type;

                var TypeOfVals = Identifiers.Recognize(Container, Left, TOptions);
                if (TypeOfVals == null)
                {
                    return(SimpleRecResult.Failed);
                }

                var RTypeOfVals = TypeOfVals.RealId as Type;
                if (RTypeOfVals == null || (RTypeOfVals.TypeFlags & TypeFlags.CanBeArrayType) == 0)
                {
                    if (Options.EnableMessages)
                    {
                        State.Messages.Add(MessageId.UnknownId, Code);
                    }

                    return(SimpleRecResult.Failed);
                }

                var StrParams = Code.Substring(ZPos + 1, Position - ZPos - 1).Trim();
                if (StrParams.IsEqual("?"))
                {
                    Ret = new NonrefArrayType(Container, TypeOfVals, null);
                    if (Options.Func == null || Options.Func(Ret))
                    {
                        return(SimpleRecResult.Succeeded);
                    }
                }
                else if (StrParams.IsEqual("*"))
                {
                    if ((RTypeOfVals.TypeFlags & TypeFlags.CanBePointer) == 0)
                    {
                        if (Options.EnableMessages)
                        {
                            State.Messages.Add(MessageId.UnknownId, Code);
                        }

                        return(SimpleRecResult.Failed);
                    }

                    Ret = new PointerAndLength(Container, TypeOfVals);
                    if (Options.Func == null || Options.Func(Ret))
                    {
                        return(SimpleRecResult.Succeeded);
                    }
                }

                var SplParams = RecognizerHelper.SplitToParameters(State, StrParams,
                                                                   ',', Options.EnableMessages, true);

                if (SplParams == null)
                {
                    return(SimpleRecResult.Failed);
                }

                if (SplParams.Length == 0 || SplParams[0].Length == 0)
                {
                    for (var i = 0; i < SplParams.Length; i++)
                    {
                        if (SplParams[i].Length > 0)
                        {
                            State.Messages.Add(MessageId.NotExpected, SplParams[i]);
                            return(SimpleRecResult.Failed);
                        }
                    }

                    var IndexCount = SplParams.Length == 0 ? 1 : SplParams.Length;
                    Ret = new RefArrayType(Container, TypeOfVals, IndexCount);
                    if (Options.Func == null || Options.Func(Ret))
                    {
                        return(SimpleRecResult.Succeeded);
                    }
                }
                else
                {
                    var Plugin = Container.GetPlugin();
                    Plugin.GetPlugin <EvaluatorPlugin>().MustBeConst = true;

                    var Lengths = new int[SplParams.Length];
                    for (var i = 0; i < SplParams.Length; i++)
                    {
                        var Node    = Expressions.CreateExpression(SplParams[i], Plugin);
                        var ConstCh = Node as ConstExpressionNode;
                        if (ConstCh == null)
                        {
                            return(SimpleRecResult.Failed);
                        }

                        if (!(ConstCh.Type is NonFloatType))
                        {
                            if (Options.EnableMessages)
                            {
                                State.Messages.Add(MessageId.MustBeInteger, StrParams);
                            }

                            return(SimpleRecResult.Failed);
                        }

                        if (!VerifyArrayLength(State, ConstCh, StrParams, Options.EnableMessages))
                        {
                            return(SimpleRecResult.Failed);
                        }

                        Lengths[i] = (int)ConstCh.Integer;
                    }

                    Ret = new NonrefArrayType(Container, TypeOfVals, Lengths);
                    if (Options.Func == null || Options.Func(Ret))
                    {
                        return(SimpleRecResult.Succeeded);
                    }
                }
            }

            return(SimpleRecResult.Unknown);
        }
Beispiel #24
0
 bool SetFinallyJump(Command TryComm, CodeScopeNode Scope, int Label, CodeString Code)
 {
     Scope.FunctionScope.NeverSkippedLabels.Add(Label);
     return(SetFinallyJump(TryComm, Scope, "_" + Label, Code));
 }
Beispiel #25
0
        public bool VerifyArrayLength(CompilerState State, ConstExpressionNode ConstNode, CodeString Code, bool EnableMessages)
        {
            if (ConstNode.Integer < 0)
            {
                if (EnableMessages)
                {
                    State.Messages.Add(MessageId.ArrayLengthTooSmall, Code);
                }

                return(false);
            }
            else if (ConstNode.Integer > int.MaxValue)
            {
                if (EnableMessages)
                {
                    State.Messages.Add(MessageId.ArrayLengthTooBig, Code);
                }

                return(false);
            }

            return(true);
        }
Beispiel #26
0
        bool CallInitializerWithCmp(CodeScopeNode Scope, ref int Index, PluginRoot Plugin, ExpressionNode Size, CodeString Code)
        {
            var CondComm = new Command(Scope, Code, CommandType.If);

            Scope.Children.Insert(Index, CondComm);
            Index++;

            var ThenScope = new CodeScopeNode(CondComm, new CodeString());

            CondComm.Children = new List <IdContainer>()
            {
                ThenScope
            };

            var CmpPlugin = ThenScope.GetPlugin();

            if (!CmpPlugin.Begin())
            {
                return(false);
            }

            var FS   = Scope.FunctionScope;
            var Self = CmpPlugin.NewNode(new IdExpressionNode(FS.SelfVariable, Code));
            var Null = CmpPlugin.NewNode(Constants.GetNullValue(Scope, Code));

            if (Self == null || Null == null)
            {
                return(false);
            }

            var CmpCh   = new ExpressionNode[] { Self, Null };
            var CmpNode = CmpPlugin.NewNode(new OpExpressionNode(Operator.RefEquality, CmpCh, Code));

            if (CmpNode == null || (CmpNode = CmpPlugin.End(CmpNode)) == null)
            {
                return(false);
            }
            CondComm.Expressions = new List <ExpressionNode>()
            {
                CmpNode
            };

            var NewIndex = ThenScope.Children.Count;

            if (!CallInitializerWithoutCmp(ThenScope, ref NewIndex, Plugin, Size, Code))
            {
                return(false);
            }
            if (!ProcessContainer(ThenScope))
            {
                return(false);
            }
            return(ProcessContainer(CondComm));
        }
 public string RefactoredCode(CodeString codeString, Func <EncapsulateFieldModel, EncapsulateFieldModel> presenterAdjustment, Type expectedException = null, bool executeViaActiveSelection = false)
 => RefactoredCode(codeString.Code, codeString.CaretPosition.ToOneBased(), presenterAdjustment, expectedException, executeViaActiveSelection);
Beispiel #28
0
        private bool SetFunctionTable(CodeScopeNode Scope, ref int Index, SelfVariable Self, CodeString Code)
        {
            var Class  = Self.TypeOfSelf.UnderlyingClassOrRealId as ClassType;
            var Plugin = Scope.GetPlugin();

            if (!Plugin.Begin())
            {
                return(false);
            }

            ExpressionNode Value;

            if (Class.HasFunctionTable)
            {
                Value = Plugin.NewNode(new LabelExpressionNode(Code, Class.FunctionTableLabel));
                if (Value == null)
                {
                    return(false);
                }
            }
            else
            {
                Value = Constants.GetNullValue(Scope, Code);
                if (Value == null)
                {
                    return(false);
                }
            }

            var Assignment = Expressions.SetValue(Self, "_objFunctionTable", Value, Plugin, Code, true);

            if (Assignment == null)
            {
                return(false);
            }

            var Command = new Command(Scope, Code, CommandType.Expression);

            Command.Expressions = new List <ExpressionNode>()
            {
                Assignment
            };
            Scope.Children.Insert(Index, Command);
            Index++;

            return(ProcessContainer(Command));
        }
        private bool HandleInternal(AutoCompleteEventArgs e, CodeString original, SelfClosingPair pair, out CodeString result)
        {
            // if executing the SCP against the original code yields no result, we need to bail out.
            if (!_scpService.Execute(pair, original, e.Character, out result))
            {
                return(false);
            }

            // let the VBE alter the original code if it wants to, then work with the prettified code.
            var prettified = CodePaneHandler.Prettify(e.Module, original);

            var isPresent = original.CaretLine.EndsWith($"{pair.OpeningChar}{pair.ClosingChar}");

            if (!isPresent && original.CaretLine.Length + 2 == prettified.CaretLine.Length &&
                prettified.CaretLine.EndsWith($"{pair.OpeningChar}{pair.ClosingChar}"))
            {
                // prettifier just added the pair for us; likely a Sub or Function statement.
                prettified = original; // pretend this didn't happen; we need to work out the caret position anyway.
            }

            if (prettified.CaretLine.Length == 0)
            {
                // prettifier destroyed the indent. need to reinstate it now.
                prettified = prettified.ReplaceLine(
                    index: prettified.CaretPosition.StartLine,
                    content: new string(' ', original.CaretLine.TakeWhile(c => c == ' ').Count())
                    );
            }

            if (original.CaretLine.EndsWith(" ") &&
                string.Equals(original.CaretLine, prettified.CaretLine + " ", StringComparison.InvariantCultureIgnoreCase))
            {
                prettified = original;
            }

            // if executing the SCP against the prettified code yields no result, we need to bail out.
            if (!_scpService.Execute(pair, prettified, e.Character, out result))
            {
                return(false);
            }

            var reprettified = CodePaneHandler.Prettify(e.Module, result);

            if (pair.OpeningChar == '(' && e.Character == pair.OpeningChar)
            {
                if (string.Equals(reprettified.Code, result.Code, StringComparison.InvariantCultureIgnoreCase))
                {
                    e.Handled = true;
                    result    = reprettified;
                    return(true);
                }

                // VBE eats it. bail out but don't swallow the keypress.
                e.Handled = false;
                result    = null;
                return(false);
            }

            var currentLine = reprettified.Lines[reprettified.CaretPosition.StartLine];

            if (!string.IsNullOrWhiteSpace(currentLine) &&
                currentLine.EndsWith(" ") &&
                reprettified.CaretPosition.StartColumn == currentLine.Length)
            {
                result = reprettified.ReplaceLine(reprettified.CaretPosition.StartLine, currentLine.TrimEnd());
            }

            if (pair.OpeningChar == '(' &&
                e.Character == pair.OpeningChar &&
                !result.CaretLine.EndsWith($"{pair.OpeningChar}{pair.ClosingChar}"))
            {
                // VBE eats it. bail out but still swallow the keypress; we already prettified the opening character into the editor.
                e.Handled = true;
                result    = null;
                return(false);
            }

            return(true);
        }
Beispiel #30
0
        private bool AllocateObject(CodeScopeNode Scope, ref int Index, SelfVariable Self, ExpressionNode Size, PluginRoot Plugin, CodeString Code)
        {
            var TypeMngrPlugin = Plugin.GetPlugin <TypeMngrPlugin>();

            TypeMngrPlugin.Flags |= TypeMngrPluginFlags.NoWarningOnCastingToSameType;
            TypeMngrPlugin.Flags |= TypeMngrPluginFlags.EnableReadonlyWriting;

            var Func = Identifiers.GetByFullNameFast <Function>(Scope.State, "Internals.ObjectHelper.Allocate");

            if (Func == null)
            {
                return(false);
            }

            var FuncNode = Plugin.NewNode(new IdExpressionNode(Func, Code));

            if (Func == null)
            {
                return(false);
            }

            var FuncType  = Func.Children[0] as TypeOfFunction;
            var SizeParam = FuncType.Children[1] as FunctionParameter;

            if (Size.Type == null || !Size.Type.IsEquivalent(SizeParam.TypeOfSelf))
            {
                Size = Expressions.Convert(Size, SizeParam.TypeOfSelf, Plugin, Code);
                if (Size == null)
                {
                    return(false);
                }
            }

            var CallCh = new ExpressionNode[] { FuncNode, Size };
            var Call   = Plugin.NewNode(new OpExpressionNode(Operator.Call, CallCh, Code));

            if (Call == null)
            {
                return(false);
            }

            var Node = Expressions.Reinterpret(Call, Self.TypeOfSelf, Plugin, Code);

            if (Node == null)
            {
                return(false);
            }

            var FS         = Scope.FunctionScope;
            var Assignment = Expressions.SetValue(FS.SelfVariable, Node, Plugin, Code, true);

            if (Assignment == null)
            {
                return(false);
            }

            var Command = new Command(Scope, Code, CommandType.Expression);

            Command.Expressions = new List <ExpressionNode>()
            {
                Assignment
            };
            Scope.Children.Insert(Index, Command);
            Index++;

            return(ProcessContainer(Command));
        }
        public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settings, out CodeString result)
        {
            result = null;
            if (!settings.SelfClosingPairs.IsEnabled || !_scpInputLookup.TryGetValue(e.Character, out var pair) && e.Character != '\b')
            {
                // not an interesting keypress.
                return(false);
            }

            var original = CodePaneHandler.GetCurrentLogicalLine(e.Module);

            if (original == null || original.Lines.Length == MaximumLines)
            {
                // selection spans more than a single logical line, or
                // logical line somehow spans more than the maximum number of physical lines in a logical line of code (25).
                return(false);
            }

            if (!original.CaretPosition.IsSingleCharacter)
            {
                // here would be an opportunity to "wrap selection" with a SCP.
                // todo: WrapSelectionWith(pair)?
                result = null;
                return(false);
            }

            if (pair != null)
            {
                // found a SCP for the input key; see if we should handle it:
                if (!HandleInternal(e, original, pair, out result))
                {
                    return(false);
                }
            }
            else if (e.Character == '\b')
            {
                // backspace - see if SCP logic needs to intervene:
                foreach (var scp in _selfClosingPairs)
                {
                    if (HandleInternal(e, original, scp, out result))
                    {
                        break;
                    }
                }
            }

            if (result == null)
            {
                // no meaningful output; let the input be handled by another handler, maybe.
                return(false);
            }

            // 1-based selection span in the code pane starts at column 1 but really encompasses the entire line.
            var snippetPosition = new Selection(result.SnippetPosition.StartLine, 1, result.SnippetPosition.EndLine, 1);

            result = new CodeString(result.Code, result.CaretPosition, snippetPosition);
            _scpService.ShowQuickInfo();
            e.Handled = true;
            return(true);
        }
 private string FilterCodeString(CodeString codeString)
 {
     var codeByte = codeString as CodeByte;
     if (codeByte != null)
         return codeByte.Value.ToString("X2");
     return "_" + LabelMap.Labels[((CodeReference)codeString).Address] + "_";
 }
Beispiel #33
0
        /// <summary>
        /// This static function returns the Re-Construted value of the particular Dicom attribute.
        /// </summary>
        /// <param name="attribute">Dicom attribute contains tag vr and value</param>
        /// <returns>Returns the value of the Dicom attribute</returns>
        public static String GetDicomValue(DvtkData.Dimse.Attribute attribute)
        {
            String dumpString = "";

            if (attribute != null && attribute.Length != 0)
            {
                switch (attribute.ValueRepresentation)
                {
                case VR.AE:
                {
                    ApplicationEntity applicationEntity = (ApplicationEntity)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(applicationEntity.Values));
                    break;
                }

                case VR.AS:
                {
                    AgeString ageString = (AgeString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(ageString.Values));
                    break;
                }

                case VR.AT:
                {
                    AttributeTag attributeTag = (AttributeTag)attribute.DicomValue;
                    Console.WriteLine("{0}", GetValues(attributeTag.Values));
                    break;
                }

                case VR.CS:
                {
                    CodeString codeString = (CodeString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(codeString.Values));
                    break;
                }

                case VR.DA:
                {
                    Date date = (Date)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(date.Values));
                    break;
                }

                case VR.DS:
                {
                    DecimalString decimalString = (DecimalString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(decimalString.Values));
                    break;
                }

                case VR.DT:
                {
                    DvtkData.Dimse.DateTime dateTime = (DvtkData.Dimse.DateTime)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(dateTime.Values));
                    break;
                }

                case VR.FD:
                {
                    FloatingPointDouble floatingPointDouble = (FloatingPointDouble)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(floatingPointDouble.Values));
                    break;
                }

                case VR.FL:
                {
                    FloatingPointSingle floatingPointSingle = (FloatingPointSingle)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(floatingPointSingle.Values));
                    break;
                }

                case VR.IS:
                {
                    IntegerString integerString = (IntegerString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(integerString.Values));
                    break;
                }

                case VR.LO:
                {
                    LongString longString = (LongString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(longString.Values));
                    break;
                }

                case VR.LT:
                {
                    LongText longText = (LongText)attribute.DicomValue;
                    dumpString += String.Format("{0}", longText.Value);
                    break;
                }

                case VR.OB:
                {
                    OtherByteString otherByteString = (OtherByteString)attribute.DicomValue;
                    dumpString += String.Format("{0}", otherByteString.FileName);
                    break;
                }

                case VR.OF:
                {
                    OtherFloatString otherFloatString = (OtherFloatString)attribute.DicomValue;
                    dumpString += String.Format("{0}", otherFloatString.FileName);
                    break;
                }

                case VR.OW:
                {
                    OtherWordString otherWordString = (OtherWordString)attribute.DicomValue;
                    dumpString += String.Format("{0}", otherWordString.FileName);
                    break;
                }

                case VR.PN:
                {
                    PersonName personName = (PersonName)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(personName.Values));
                    break;
                }

                case VR.SH:
                {
                    ShortString shortString = (ShortString)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(shortString.Values));
                    break;
                }

                case VR.SL:
                {
                    SignedLong signedLong = (SignedLong)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(signedLong.Values));
                    break;
                }

                case VR.SQ:
                {
                    //SequenceOfItems sequenceOfItems = (SequenceOfItems)attribute.DicomValue;
                    //int itemNumber = 1;
                    //dumpString += "\r\n";
                    //foreach (SequenceItem item in sequenceOfItems.Sequence)
                    //{
                    //    dumpString += String.Format("> Begin Item: {0}\r\n", itemNumber);
                    //    dumpString += item.Dump(prefix);
                    //    dumpString += prefix + String.Format("> End Item: {0}\r\n", itemNumber++);
                    //}
                    break;
                }

                case VR.SS:
                {
                    SignedShort signedShort = (SignedShort)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(signedShort.Values));
                    break;
                }

                case VR.ST:
                {
                    ShortText shortText = (ShortText)attribute.DicomValue;
                    dumpString += String.Format("{0}", shortText.Value);
                    break;
                }

                case VR.TM:
                {
                    Time time = (Time)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(time.Values));
                    break;
                }

                case VR.UI:
                {
                    UniqueIdentifier uniqueIdentifier = (UniqueIdentifier)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(uniqueIdentifier.Values));
                    break;
                }

                case VR.UL:
                {
                    UnsignedLong unsignedLong = (UnsignedLong)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(unsignedLong.Values));
                    break;
                }

                case VR.UN:
                {
                    break;
                }

                case VR.US:
                {
                    UnsignedShort unsignedShort = (UnsignedShort)attribute.DicomValue;
                    dumpString += String.Format("{0}", GetValues(unsignedShort.Values));
                    break;
                }

                case VR.UT:
                {
                    break;
                }

                case VR.UR:
                {
                    break;
                }

                case VR.UC:
                {
                    break;
                }

                default:
                    dumpString += String.Format("\'  \'");
                    break;
                }
            }
            else
            {
                dumpString += String.Format("\'  \'");
            }


            return(dumpString);
        }