Example #1
0
        public static CommonGraph ToCommonCgraph(NodeGraph nodegraph)
        {
            var g = new CommonGraph();

            g.Nodes = nodegraph.Nodes;
            g.Edges = nodegraph.Connectors;
            return(g);
        }
Example #2
0
        public GH_FileComposer(CommonGraph cg)
        {
            graph = cg;

            doc = XDocument.Parse(graph.MetaData.Ignore);

            //File.WriteAllText(@"C:\Users\aheumann\Desktop\xml out test.txt", graph.MetaData.Ignore);


            ConstructGH();
        }
Example #3
0
        private async void OnShowCommonModel(CommonGraph commonModel)
        {
            CommonModelViewer viewer = new CommonModelViewer
            {
                Graph               = commonModel,
                Margin              = new Thickness(5),
                MaxWidth            = 600,
                MaxHeight           = 600,
                VerticalAlignment   = VerticalAlignment.Stretch,
                HorizontalAlignment = HorizontalAlignment.Stretch
            };

            await DialogHost.Show(viewer, "RootDialog");
        }
Example #4
0
        static void Main(string[] args)
        {
            string filePath = args[0];
            //Console.WriteLine(filePath);
            CommonGraph   dg            = Parser.CommonGraphFromGHFile(filePath);
            XmlSerializer SerializerObj = new XmlSerializer(typeof(CommonGraph));
            string        dest          = filePath.Replace(Path.GetExtension(filePath), ".cgx");

            //Console.WriteLine(args.Length.ToString());
            if (args.Length > 1)
            {
                dest = args[1];
            }
            TextWriter WriteFileStream = new StreamWriter(dest);

            SerializerObj.Serialize(WriteFileStream, dg);


            //Console.ReadKey();
        }
Example #5
0
 private void OnRemoveCommonModel(CommonGraph commonModel)
 {
     CommonGraphs.Remove(commonModel);
     _intermediaryCommonModels.Remove(commonModel.BasedOn);
 }
Example #6
0
        //Actual constructor for use in the program
        public static CommonGraph CommonGraphFromGHFile(string file)
        {
            CommonGraph cg = new CommonGraph();



            //construct GH Archive object for XML Traversal
            GH_Archive archive = new GH_Archive();

            archive.ReadFromFile(file);

            MetaData graphMetaData = new MetaData();

            graphMetaData.Ignore = archive.Serialize_Xml();
            cg.MetaData          = graphMetaData;

            //traverse GH file tree
            var rootNode   = archive.GetRootNode;
            var definition = rootNode.FindChunk("Definition");
            var defObjects = definition.FindChunk("DefinitionObjects");
            int objCount   = defObjects.GetInt32("ObjectCount");


            //for every object in the definition object list:
            for (int i = 0; i < objCount; i++)
            {
                var singleObjectChunk = defObjects.Chunks[i] as GH_Chunk;

                Guid typeGuid = singleObjectChunk.GetGuid("GUID");

                var container = singleObjectChunk.FindChunk("Container");

                var attributes = container.FindChunk("Attributes");



                Guid   instanceGuid = container.GetGuid("InstanceGuid");
                string name         = singleObjectChunk.GetString("Name");

                IEnumerable <GH_IChunk> inputs;
                IEnumerable <GH_IChunk> outputs;

                //Components that implement variable parameters store their inputs/outputs one layer deeper.
                var  parameterData    = container.Chunks.Where <GH_IChunk>(C => C.Name == "ParameterData");
                bool hasParameterData = parameterData.Count() > 0;

                bool hasSourceCount = container.ItemExists("SourceCount");

                var paramChunks = container.Chunks;
                if (hasParameterData)
                {
                    paramChunks = parameterData.ToList()[0].Chunks;
                    inputs      = paramChunks.Where(C => C.Name == "InputParam");
                    outputs     = paramChunks.Where(C => C.Name == "OutputParam");
                }
                else
                {
                    inputs  = paramChunks.Where(C => C.Name == "param_input");
                    outputs = paramChunks.Where(C => C.Name == "param_output");
                }



                bool hasInputs  = inputs.Count() > 0;
                bool hasOutputs = outputs.Count() > 0;

                bool isComponent = hasInputs || hasOutputs || hasParameterData;

                bool isActiveObject = isComponent || hasSourceCount;



                //Debugging
                //Console.WriteLine(name);
                //Console.WriteLine("Is active object? " + isActiveObject.ToString());
                //Console.WriteLine("Is Component? " + isComponent.ToString());


                if (!isActiveObject)
                {
                    continue;
                }


                Node node = new Node();
                //type and instance
                node.Type         = typeGuid.ToString();
                node.InstanceGuid = instanceGuid.ToString();
                node.Name         = name;
                Position pos = new Position();
                try
                {
                    var locPoint = attributes.GetDrawingPointF("Pivot");
                    pos.X = locPoint.X;
                    pos.Y = locPoint.Y;
                }
                catch { }
                node.Position = pos;

                //Metadata
                MetaData md = new MetaData();
                md.Ignore = chunkToXmlString(singleObjectChunk);
                //TODO - REMOVE COMPONENTS OF XML THAT SHOULDN'T BE INSPECTED
                md.Inspect    = chunkToXmlString(singleObjectChunk);
                node.MetaData = md;

                List <Port> ports = new List <Port>();
                List <Edge> edges = new List <Edge>();
                if (isComponent) //if it's a component
                {
                    List <GH_IChunk> portChunks = new List <GH_IChunk>();
                    portChunks.AddRange(inputs);
                    portChunks.AddRange(outputs);


                    foreach (var portIChunk in portChunks) // for every port "chunk"
                    {
                        Port     port             = new Port();
                        GH_Chunk portChunk        = portIChunk as GH_Chunk;
                        Guid     portInstanceGuid = portChunk.GetGuid("InstanceGuid");
                        port.InstanceGuid = portInstanceGuid.ToString();
                        port.Name         = portChunk.GetString("Name");
                        MetaData portMetadata = new MetaData();
                        portMetadata.Ignore = chunkToXmlString(portChunk);
                        port.MetaData       = portMetadata; //REMEMBER TO UNCOMMENT
                        ports.Add(port);



                        var sources = portChunk.Items.Where(item => item.Name == "Source");
                        //Console.WriteLine("WE GOT THIS MANY SOURCES:" +sources.Count());
                        foreach (GH_Item item in sources)
                        {
                            //Console.WriteLine("EDGE");
                            Edge edge = new Edge();
                            edge.DestGuid = portInstanceGuid.ToString();
                            edge.SrcGuid  = item._guid.ToString();
                            edges.Add(edge);
                        }
                    }
                }
                else if (!isComponent && isActiveObject) //if it's a param
                {
                    Port port = new Port();
                    //wrapper for object - if it's a param, instance for virtual node and port are the same.
                    Guid portInstanceGuid = instanceGuid;
                    port.InstanceGuid = instanceGuid.ToString();
                    port.Name         = name;
                    ports.Add(port);

                    var sources = container.Items.Where(item => item.Name == "Source");

                    foreach (GH_Item source in sources)
                    {
                        Edge edge = new Edge();
                        edge.DestGuid = portInstanceGuid.ToString();
                        edge.SrcGuid  = source._guid.ToString();
                        edges.Add(edge);
                    }
                }

                node.Ports = ports;
                cg.Edges.AddRange(edges);
                cg.Nodes.Add(node);
            }

            return(cg);
        }