コード例 #1
0
ファイル: SOPClassUIDBuilder.cs プロジェクト: zzti/Evil-DICOM
        internal static void BuildSOPClassDictionary(string filePath)
        {
            var g    = GeneratorBuilder.Instance.Generator;
            var type = g.IdentifierName("Dictionary<string, SOPClass>");

            var sopClass = DICOMDefinitionLoader.LoadCurrentSOPClasses();
            List <SyntaxNode> methodStatements = new List <SyntaxNode>();

            methodStatements.Add(g.AssignmentStatement(g.IdentifierName("var dict"), g.ObjectCreationExpression(type)));

            foreach (var sop in sopClass)
            {
                methodStatements.Add(g.InvocationExpression(g.IdentifierName("dict.Add"),
                                                            g.Argument(RefKind.None, g.IdentifierName($"SOPClassUID.{sop.Keyword}")),
                                                            g.Argument(RefKind.None, g.IdentifierName($"SOPClass.{sop.Keyword}"))));
            }

            methodStatements.Add(g.ReturnStatement(g.IdentifierName("dict")));

            //SOPClass enum
            var method = g.MethodDeclaration("Initialize", null, null, type, Accessibility.Internal,
                                             DeclarationModifiers.Static, methodStatements);
            var cls = g.ClassDeclaration("SOPClassDictionary", null, Accessibility.Internal,
                                         DeclarationModifiers.None, null, null, new SyntaxNode[] { method });
            var namespaceDeclaration = g.NamespaceDeclaration("EvilDICOM.Core.Helpers", cls);

            cls = g.CompilationUnit(UsingsHelper.GetUsings().Concat(new SyntaxNode[] { namespaceDeclaration })).NormalizeWhitespace();
            File.WriteAllText(filePath, cls.NormalizeWhitespace().ToString());
        }
コード例 #2
0
ファイル: SOPClassUIDBuilder.cs プロジェクト: zzti/Evil-DICOM
        internal static void BuildSOPClassUIDs(string filePath)
        {
            var g        = GeneratorBuilder.Instance.Generator;
            var sopClass = DICOMDefinitionLoader.LoadCurrentSOPClasses();
            List <SyntaxNode> sopFields = new List <SyntaxNode>();

            foreach (var sop in sopClass)
            {
                var name = sop.Keyword;
                //public static string VERIFICATION = "1.2.840.10008.1.1";
                var f = g.FieldDeclaration(name, g.IdentifierName("String"), Accessibility.Public,
                                           DeclarationModifiers.Const, g.LiteralExpression(sop.Id));
                sopFields.Add(f);
            }

            //SOPClassUID
            var sopNode = g.ClassDeclaration("SOPClassUID",
                                             null,
                                             Accessibility.Public,
                                             DeclarationModifiers.Partial, null, null, sopFields);
            var namespaceDeclaration = g.NamespaceDeclaration("EvilDICOM.Core.Helpers", sopNode);

            sopNode = g.CompilationUnit(UsingsHelper.GetUsings().Concat(new SyntaxNode[] { namespaceDeclaration })).NormalizeWhitespace();

            File.WriteAllText(filePath, sopNode.NormalizeWhitespace().ToString());
        }
コード例 #3
0
ファイル: SOPClassUIDBuilder.cs プロジェクト: zzti/Evil-DICOM
        internal static void BuildSOPClass(string filePath)
        {
            var g        = GeneratorBuilder.Instance.Generator;
            var sopClass = DICOMDefinitionLoader.LoadCurrentSOPClasses();

            List <SyntaxNode> enumMembers = new List <SyntaxNode>();

            foreach (var sop in sopClass)
            {
                var name = sop.Keyword;

                enumMembers.Add(g.EnumMember(sop.Keyword));
            }
            enumMembers.Add(g.EnumMember("Unknown"));

            //SOPClass enum
            var sopclassNode = g.EnumDeclaration("SOPClass", Accessibility.Public, DeclarationModifiers.None,
                                                 enumMembers);
            var namespaceDeclaration = g.NamespaceDeclaration("EvilDICOM.Core.Enums", sopclassNode);

            sopclassNode = g.CompilationUnit(new SyntaxNode[] { namespaceDeclaration }).NormalizeWhitespace();
            File.WriteAllText(filePath, sopclassNode.NormalizeWhitespace().ToString());
        }
コード例 #4
0
        static void Main(string[] args)
        {
            var ionPlan = DomainBuilder.BuildFromFile(@"D:\CALIBRATION_2.5SS_10x10_50MUPS.dcm", "IonPlan");

            DomainWriter.WriteObjects(ionPlan, @"D:\DomainObjects");
            //SOPClassUIDBuilder.BuildSOPClassUIDs(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\Helpers\SOPClassUID.cs");
            //SOPClassUIDBuilder.BuildSOPClassDictionary(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\Helpers\SOPClassDictionary.cs");
            //SOPClassUIDBuilder.BuildSOPClass(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\Enums\SOPClass.cs");
            var g = GeneratorBuilder.Instance.Generator;

            //DICOMDefinitionLoader.UpdateCurrentFromWeb();
            var dictionary = DICOMDictionary.Instance.Entries;

            // Get Anonymization tags
            var anonTags = DICOMDefinitionLoader.LoadAnonymizationTags().ToList();

            var forgeNodes         = new List <SyntaxNode>();
            var tags               = new List <SyntaxNode>();
            var selectors          = new List <SyntaxNode>();
            var seqSelectors       = new List <SyntaxNode>();
            var anonymizationNodes = new List <SyntaxNode>();

            List <SyntaxNode> anonProfile = new List <SyntaxNode>();

            anonProfile.Add(g.AssignmentStatement(g.IdentifierName("var profile"), g.IdentifierName("new List<IDICOMElement>()")));
            foreach (var atag in anonTags)
            {
                var action = "AnonymizeAction.REMOVE_ELEMENT";
                switch (atag.Metadata)
                {
                case "D": action = "AnonymizeAction.DUMMY_DATA"; break;

                case "Z":
                case "Z/D": action = "AnonymizeAction.NULL_DATA"; break;

                case "X/Z":
                case "X/D":
                case "X/Z/D":
                case "X": action = "AnonymizeAction.REMOVE_ELEMENT"; break;

                case "K":
                case "C": action = "AnonymizeAction.CLEAN"; break;

                case "X/Z/U*":
                case "U": action = "AnonymizeAction.CLEAN"; break;
                }
                atag.VR = dictionary.FirstOrDefault(d => d.Id == atag.Id)?.VR;
                var entry = g.IdentifierName($"yield return new ConfidentialElement(){{Id=\"{atag.Id}\", ElementName=\"{atag.Name}\", VR=VR.{VRDictionary.GetVRFromAbbreviation(atag.VR)}, Action = {action}}} )");
                anonProfile.Add(entry);
            }
            anonProfile.Add(g.ReturnStatement(g.IdentifierName("profile")));

            var method = g.MethodDeclaration("GenerateProfileElements", null, null, g.IdentifierName("List<IDICOMElement>"), Accessibility.Public, DeclarationModifiers.Static, anonProfile);

            var anonNode = g.ClassDeclaration("AnonStub",
                                              null,
                                              Accessibility.Public,
                                              DeclarationModifiers.Static, null, null, new SyntaxNode[] { method });
            var anonMethod = g.CompilationUnit(anonNode).NormalizeWhitespace().ToString();



            foreach (var entry in dictionary.Where(d => !string.IsNullOrEmpty(d.Keyword)))
            {
                //Build a tag no matter what
                tags.Add(TagBuilder.Generate(g, entry));

                var(cName, parameter) = EntryParser.Parse(g, entry);

                if (cName != null)
                {
                    //SELECTOR
                    var(propGetStatements, propSetStatements) = SelectorBuilder.GeneratePropertyStatements(g, cName, entry);
                    var sel = g.PropertyDeclaration(entry.Keyword, g.IdentifierName(cName), Accessibility.Public,
                                                    DeclarationModifiers.None, propGetStatements, propSetStatements);
                    selectors.Add(sel);
                    seqSelectors.Add(g.PropertyDeclaration(entry.Keyword, g.IdentifierName(cName), Accessibility.Public,
                                                           DeclarationModifiers.ReadOnly, SelectorBuilder.GenerateSequencePropertyStatements(g, cName, entry), null));

                    // return _dicom.FindAll("00000000").Select(d => d as UnsignedLong).ToList();
                    var returnMany = g.ReturnStatement(g.InvocationExpression(
                                                           g.IdentifierName($"_dicom.FindAll(\"{entry.Id}\").Select(d => d as {cName}).ToList")));
                    var returnManySeq = g.ReturnStatement(g.InvocationExpression(
                                                              g.IdentifierName($"Items.FindAll<{cName}>(\"{entry.Id}\").ToList")));
                    selectors.Add(g.PropertyDeclaration(entry.Keyword + "_", g.IdentifierName($"List<{cName}>"),
                                                        Accessibility.Public, DeclarationModifiers.ReadOnly, new SyntaxNode[] { returnMany }));
                    var selSeqProp = g.PropertyDeclaration(entry.Keyword + "_", g.IdentifierName($"List<{cName}>"),
                                                           Accessibility.Public, DeclarationModifiers.ReadOnly, new SyntaxNode[] { returnManySeq });

                    seqSelectors.Add(selSeqProp);
                    //FORGE
                    var methStatements = new SyntaxNode[]
                    {
                        // return new UnsignedLong { Tag = new Tag("00000001") };
                        g.AssignmentStatement(g.IdentifierName("var element"),
                                              g.ObjectCreationExpression(g.IdentifierName(cName))),
                        g.AssignmentStatement(g.IdentifierName("element.Tag"),
                                              g.ObjectCreationExpression(g.IdentifierName("Tag"),
                                                                         g.Argument(RefKind.None, g.LiteralExpression(entry.Id)))),
                        g.AssignmentStatement(g.IdentifierName("element.Data_"), g.IdentifierName("data?.ToList()")),
                        g.ReturnStatement(g.IdentifierName("element"))
                    };

                    var m = g.MethodDeclaration(entry.Keyword, new SyntaxNode[] { parameter }, null, g.IdentifierName(cName), Accessibility.Public,
                                                DeclarationModifiers.Static, methStatements);
                    forgeNodes.Add(m);
                }
            }



            var forgeNode = g.ClassDeclaration("DICOMForge",
                                               null,
                                               Accessibility.Public,
                                               DeclarationModifiers.Static, null, null, forgeNodes);
            var namespaceDeclaration = g.NamespaceDeclaration("EvilDICOM.Core", forgeNode);

            forgeNode = g.CompilationUnit(UsingsHelper.GetUsings().Concat(new SyntaxNode[] { namespaceDeclaration })).NormalizeWhitespace();
            //public UnsignedLong CommandGroupLength
            //{
            //    get { return _dicom.FindFirst("00000000") as UnsignedLong; }
            //set { _dicom.ReplaceOrAdd(value); }
            //}

            var tagHelperNode = g.ClassDeclaration("TagHelper",
                                                   null,
                                                   Accessibility.Public,
                                                   DeclarationModifiers.Static, null, null, tags);

            namespaceDeclaration = g.NamespaceDeclaration("EvilDICOM.Core.Helpers", tagHelperNode);
            tagHelperNode        = g.CompilationUnit(UsingsHelper.GetUsings().Concat(new SyntaxNode[] { namespaceDeclaration })).NormalizeWhitespace();

            var selectorNode = g.ClassDeclaration("DICOMSelector",
                                                  null,
                                                  Accessibility.Public,
                                                  DeclarationModifiers.Partial, null, null, selectors);

            namespaceDeclaration = g.NamespaceDeclaration("EvilDICOM.Core.Selection", selectorNode);
            selectorNode         = g.CompilationUnit(UsingsHelper.GetUsings().Concat(new SyntaxNode[] { namespaceDeclaration })).NormalizeWhitespace();

            var selectorSeqNode = g.ClassDeclaration("SequenceSelector",
                                                     null,
                                                     Accessibility.Public,
                                                     DeclarationModifiers.Partial, g.IdentifierName("AbstractElement<DICOMSelector>"), null, seqSelectors);

            namespaceDeclaration = g.NamespaceDeclaration("EvilDICOM.Core.Selection", selectorSeqNode);
            selectorSeqNode      = g.CompilationUnit(UsingsHelper.GetUsings().Concat(new SyntaxNode[] { namespaceDeclaration })).NormalizeWhitespace();

            //File.WriteAllText(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\DICOMForge.cs", forgeNode.NormalizeWhitespace().ToString());
            //File.WriteAllText(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\Helpers\TagHelper.cs", tagHelperNode.NormalizeWhitespace().ToString());
            File.WriteAllText(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\Selection\DICOMSelectorProperties.cs", selectorNode.NormalizeWhitespace().ToString());
            File.WriteAllText(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\Selection\SequenceSelectorProperties.cs", selectorSeqNode.NormalizeWhitespace().ToString());
        }
コード例 #5
0
 private DICOMDictionary()
 {
     Entries = DICOMDefinitionLoader.LoadCurrentDictionary().ToList();
 }
コード例 #6
0
        static void Main(string[] args)
        {
            SOPClassUIDBuilder.BuildSOPClassUIDs(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\Helpers\SOPClassUID.cs");
            SOPClassUIDBuilder.BuildSOPClassDictionary(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\Helpers\SOPClassDictionary.cs");
            SOPClassUIDBuilder.BuildSOPClass(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\Enums\SOPClass.cs");
            var g = GeneratorBuilder.Instance.Generator;

            //DICOMDefinitionLoader.UpdateCurrentFromWeb();
            var dictionary = DICOMDefinitionLoader.LoadCurrentDictionary();

            var forgeNodes = new List <SyntaxNode>();
            var tags       = new List <SyntaxNode>();
            var selectors  = new List <SyntaxNode>();

            foreach (var entry in dictionary.Where(d => !string.IsNullOrEmpty(d.Keyword)))
            {
                //Build a tag no matter what
                tags.Add(TagBuilder.Generate(g, entry));

                var(cName, parameter) = EntryParser.Parse(g, entry);

                if (cName != null)
                {
                    //SELECTOR
                    var(propGetStatements, propSetStatements) = SelectorBuilder.GeneratePropertyStatements(g, cName, entry);
                    var sel = g.PropertyDeclaration(entry.Keyword, g.IdentifierName(cName), Accessibility.Public,
                                                    DeclarationModifiers.None, propGetStatements, propSetStatements);
                    selectors.Add(sel);

                    // return _dicom.FindAll("00000000").Select(d => d as UnsignedLong).ToList();
                    var returnMany = g.ReturnStatement(g.InvocationExpression(
                                                           g.IdentifierName($"_dicom.FindAll(\"{entry.Id}\").Select(d => d as {cName}).ToList")));

                    selectors.Add(g.PropertyDeclaration(entry.Keyword + "_", g.IdentifierName($"List<{cName}>"),
                                                        Accessibility.Public, DeclarationModifiers.None, new SyntaxNode[] { returnMany }));


                    //FORGE
                    var methStatements = new SyntaxNode[]
                    {
                        // return new UnsignedLong { Tag = new Tag("00000001") };
                        g.AssignmentStatement(g.IdentifierName("var element"),
                                              g.ObjectCreationExpression(g.IdentifierName(cName))),
                        g.AssignmentStatement(g.IdentifierName("element.Tag"),
                                              g.ObjectCreationExpression(g.IdentifierName("Tag"),
                                                                         g.Argument(RefKind.None, g.LiteralExpression(entry.Id)))),
                        g.AssignmentStatement(g.IdentifierName("element.Data_"), g.IdentifierName("data?.ToList()")),
                        g.ReturnStatement(g.IdentifierName("element"))
                    };

                    var m = g.MethodDeclaration(entry.Keyword, new SyntaxNode[] { parameter }, null, g.IdentifierName(cName), Accessibility.Public,
                                                DeclarationModifiers.Static, methStatements);
                    forgeNodes.Add(m);
                }
            }



            var forgeNode = g.ClassDeclaration("DICOMForge",
                                               null,
                                               Accessibility.Public,
                                               DeclarationModifiers.Static, null, null, forgeNodes);
            var namespaceDeclaration = g.NamespaceDeclaration("EvilDICOM.Core", forgeNode);

            forgeNode = g.CompilationUnit(UsingsHelper.GetUsings().Concat(new SyntaxNode[] { namespaceDeclaration })).NormalizeWhitespace();
            //public UnsignedLong CommandGroupLength
            //{
            //    get { return _dicom.FindFirst("00000000") as UnsignedLong; }
            //set { _dicom.ReplaceOrAdd(value); }
            //}

            var tagHelperNode = g.ClassDeclaration("TagHelper",
                                                   null,
                                                   Accessibility.Public,
                                                   DeclarationModifiers.Static, null, null, tags);

            namespaceDeclaration = g.NamespaceDeclaration("EvilDICOM.Core.Helpers", tagHelperNode);
            tagHelperNode        = g.CompilationUnit(UsingsHelper.GetUsings().Concat(new SyntaxNode[] { namespaceDeclaration })).NormalizeWhitespace();

            var selectorNode = g.ClassDeclaration("DICOMSelector",
                                                  null,
                                                  Accessibility.Public,
                                                  DeclarationModifiers.Partial, null, null, selectors);

            namespaceDeclaration = g.NamespaceDeclaration("EvilDICOM.Core.Selection", selectorNode);
            selectorNode         = g.CompilationUnit(UsingsHelper.GetUsings().Concat(new SyntaxNode[] { namespaceDeclaration })).NormalizeWhitespace();

            File.WriteAllText(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\DICOMForge.cs", forgeNode.NormalizeWhitespace().ToString());
            File.WriteAllText(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\Helpers\TagHelper.cs", tagHelperNode.NormalizeWhitespace().ToString());
            File.WriteAllText(@"D:\OneDrive\Cardan.Code\Git\Evil-DICOM\EvilDICOM\EvilDICOM\Core\Selection\DICOMSelectorProperties.cs", selectorNode.NormalizeWhitespace().ToString());
        }