private static void AddingNodesToGraph(designGraph assemblyGraph, List <TessellatedSolid> solids) //,
                                                                                                   //Dictionary<TessellatedSolid, double[]> gears)
 {
     foreach (var solid in solids)
     {
         var Component = assemblyGraph.addNode(solid.Name);
         //if (gears.Keys.Contains(solid))
         //{
         //    Component.localLabels.Add(DisConstants.Gear);
         //    Component.localVariables.Add(DisConstants.GearNormal);
         //    Component.localVariables.AddRange(gears[solid]);
         //}
     }
 }
 private static void AddingNodesToGraph(designGraph assemblyGraph, Dictionary <string, List <TessellatedSolid> > solids)//,
 //Dictionary<TessellatedSolid, double[]> gears)
 {
     foreach (var solidName in solids.Keys)
     {
         assemblyGraph.addNode(solidName, typeof(Component));
         var c = (Component)assemblyGraph.nodes.Last();
         c.CenterOfMass = COMCalculator(solids[solidName]);
         c.Volume       = solids[solidName].Sum(s => s.Volume);
         c.Mass         = solids[solidName].Sum(s => s.Volume);
         //if (gears.Keys.Contains(solid))
         //{
         //    Component.localLabels.Add(DisConstants.Gear);
         //    Component.localVariables.Add(DisConstants.GearNormal);
         //    Component.localVariables.AddRange(gears[solid]);
         //}
     }
 }
        public designGraph moltoDesignGraph(OBMol mol)
        {
            //OBConversion obconv = new OBConversion ();
            designGraph  host   = new designGraph();
            OBConversion obconv = new OBConversion();

            Dictionary <uint, int> atomid2nodeid = new Dictionary <uint, int>();



            //obconv.SetInFormat("smi");
            //var format =obconv.GetInFormat();
            //uint d=mol.NumAtoms();
            OBElementTable ptable = new OBElementTable();

            //mol.FindTorsions ();
            int nodecount = 0;

            //loop through all atoms in the file and make them into nodes in the graph
            foreach (OBAtom a in mol.Atoms())
            {
                node n = new node();
                n.name = "n" + nodecount;


                var atype = a.GetAtomType();
                n.X = a.GetX() * (1 / scale);
                n.Y = a.GetY() * (1 / scale);
                n.Z = a.GetZ() * (1 / scale);

                uint   anum = a.GetAtomicNum();
                string sym  = ptable.GetSymbol((int)anum);
                //double test =ptable.GetIonization ((int)anum);
                int  maxbonds = ptable.GetMaxBonds((int)anum);
                uint val      = a.GetImplicitValence();
                n.localLabels.Add(sym);
                n.localLabels.Add(atype);
                n.localVariables.Add((double)maxbonds);
                n.localVariables.Add((double)val);
                host.addNode(n);
                atomid2nodeid.Add(a.GetId(), nodecount);
                //Console.WriteLine (x);
                nodecount++;
            }
            int arccount = 0;

            foreach (OBBond b in mol.Bonds())
            {
                arc ac = new arc();
                ac.directed = false;
                ac.name     = "a" + arccount;
                //uint bondorder = b.GetBondOrder ();

                if (b.IsSingle())
                {
                    ac.localLabels.Add("s");
                }
                if (b.IsTriple())
                {
                    ac.localLabels.Add("t");
                }
                if (b.IsDouble())
                {
                    ac.localLabels.Add("d");
                }
                uint toid   = b.GetEndAtomIdx();
                uint fromid = b.GetBeginAtomIdx();
                ac.To   = host.nodes[atomid2nodeid[toid - 1]];
                ac.From = host.nodes[atomid2nodeid[fromid - 1]];
                host.arcs.Add(ac);
                arccount++;
            }
            return(host);
        }
        public override void Paste()
        {
            var ClipboardString = Clipboard.GetText();
            var copiedSelection = SelectionClass.DeSerializeClipboardFormatFromXML(ClipboardString);

            RestoreDisplayShapes(copiedSelection.ReadInXmlShapes, copiedSelection.selectedNodes,
                                 copiedSelection.selectedArcs, copiedSelection.selectedHyperArcs);
            var newSelection = new List <UIElement>();

            if (copiedSelection != null)
            {
                var tempGraph = new designGraph();
                foreach (node n in copiedSelection.selectedNodes)
                {
                    if (n is ruleNode)
                    {
                        tempGraph.addNode(n);
                    }
                    else
                    {
                        tempGraph.addNode(new ruleNode(n));
                    }
                }
                foreach (arc a in copiedSelection.selectedArcs)
                {
                    if (a is ruleArc)
                    {
                        tempGraph.arcs.Add(a);
                    }
                    else
                    {
                        tempGraph.arcs.Add(new ruleArc(a));
                    }
                }
                foreach (hyperarc a in copiedSelection.selectedHyperArcs)
                {
                    if (a is ruleHyperarc)
                    {
                        tempGraph.addHyperArc(a);
                    }
                    else
                    {
                        tempGraph.addHyperArc(new ruleHyperarc(a));
                    }
                }
                tempGraph.RepairGraphConnections();

                foreach (node n in tempGraph.nodes)
                {
                    var mousePos = Mouse.GetPosition(this);
                    n.X    = mousePos.X + n.X - copiedSelection.ReferencePoint.X - Origin.X;
                    n.Y    = mousePos.Y + n.Y - copiedSelection.ReferencePoint.Y - Origin.Y;
                    n.name = rW.rule.makeUniqueNodeName(n.name);
                    addNodeShape(n);
                    graph.addNode(n);
                    newSelection.Add((Shape)n.DisplayShape.Shape);

                    if (rW.graphGUIK == this)
                    {
                        AddKNodeToLandR(n);
                    }
                }
                foreach (arc a in tempGraph.arcs)
                {
                    a.name = rW.rule.makeUniqueArcName(a.name);
                    graph.arcs.Add(a);
                    AddArcShape(a);
                    SetUpNewArcShape(a);
                    newSelection.Add((ArcShape)a.DisplayShape.Shape);

                    if (rW.graphGUIK == this)
                    {
                        AddKArcToLandR(a);
                    }
                }
                foreach (hyperarc h in tempGraph.hyperarcs)
                {
                    h.name = rW.rule.makeUniqueHyperarcName(h.name);
                    graph.addHyperArc(h);
                    AddHyperArcShape(h);
                    newSelection.Add((HyperArcShape)h.DisplayShape.Shape);

                    if (rW.graphGUIK == this)
                    {
                        AddKHyperToLandR(h);
                    }
                }
                Select(newSelection);
            }
        }