Exemple #1
0
        internal override void Create_BR(TransientGeometry TG, ref PlanarSketch sketch, EdgeCollection eColl, ref Face B_face, ref Face E_face, ref PartComponentDefinition partDef)
        {
            ChamferFeature chamf_Feature;

            switch (Side)
            {
            case ('r'):
                try
                {
                    eColl.Add(B_face.Edges[1]);
                }
                catch
                {
                    MessageBox.Show("Catch r");
                    //eColl.Add(B_face.Edges[2]);
                }
                chamf_Feature = partDef.Features.ChamferFeatures.AddUsingDistance(eColl, Distance);
                break;

            case ('l'):
                try
                {
                    eColl.Add(E_face.Edges[2]);
                }
                catch
                {
                    MessageBox.Show("Catch l");
                    //eColl.Add(E_face.Edges[1]);
                }
                chamf_Feature = partDef.Features.ChamferFeatures.AddUsingDistance(eColl, Distance);
                break;
            }
        }
        public void ClearVertex(IVertex v)
        {
            if (v == null)
            {
                throw new ArgumentNullException("v");
            }
            if (!this.ContainsVertex(v))
            {
                throw new ArgumentException("v is not part of the graph");
            }

            EdgeCollection edges = new EdgeCollection();

            foreach (IEdge e in this.VisitedGraph.OutEdges(v))
            {
                edges.Add(e);
            }
            foreach (IEdge e in this.VisitedGraph.InEdges(v))
            {
                edges.Add(e);
            }

            foreach (IEdge e in edges)
            {
                if (this.VisitedGraph.ContainsEdge(e))
                {
                    RemoveEdge(e);
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Add a new vertex from source to target
        ///
        /// Complexity: 2 search + 1 insertion
        /// </summary>
        /// <param name="source">Source vertex</param>
        /// <param name="target">Target vertex</param>
        /// <returns>Created Edge</returns>
        /// <exception cref="ArgumentNullException">source or target is null</exception>
        /// <exception cref="Exception">source or target are not part of the graph</exception>
        public virtual IEdge AddEdge(
            IVertex source,
            IVertex target
            )
        {
            // look for the vertex in the list
            if (!VertexOutEdges.ContainsKey(source))
            {
                throw new VertexNotFoundException("Could not find source vertex");
            }
            if (!VertexOutEdges.ContainsKey(target))
            {
                throw new VertexNotFoundException("Could not find target vertex");
            }

            // if parralel edges are not allowed check if already in the graph
            if (!this.AllowParallelEdges)
            {
                if (ContainsEdge(source, target))
                {
                    return(null);
                }
            }

            // create edge
            IEdge e = Provider.ProvideEdge(source, target);

            VertexOutEdges[source].Add(e);
            m_Edges.Add(e);

            return(e);
        }
Exemple #4
0
        /// <summary>
        /// Remove the edge (u,v) from the graph.
        /// If the graph allows parallel edges this remove all occurrences of
        /// (u,v).
        /// </summary>
        /// <param name="u">source vertex</param>
        /// <param name="v">target vertex</param>
        public virtual void RemoveEdge(IVertex u, IVertex v)
        {
            if (u == null)
            {
                throw new ArgumentNullException("source vertex");
            }
            if (v == null)
            {
                throw new ArgumentNullException("targetvertex");
            }

            EdgeCollection edges = VertexOutEdges[u];
            // marking edges to remove
            EdgeCollection removedEdges = new EdgeCollection();

            foreach (IEdge e in edges)
            {
                if (e.Target == v)
                {
                    removedEdges.Add(e);
                }
            }
            //removing edges
            foreach (IEdge e in removedEdges)
            {
                edges.Remove(e);
                m_Edges.Remove(e);
            }
        }
        public static void createFillet(PartDocument oDoc)
        {
            SheetMetalComponentDefinition oCompDef = (SheetMetalComponentDefinition)oDoc.ComponentDefinition;

            SheetMetalFeatures sFeatures = (SheetMetalFeatures)oCompDef.Features;

            foreach (Edge oEdge in oCompDef.SurfaceBodies[1].ConcaveEdges)
            {
                int tmpCount = oCompDef.SurfaceBodies[1].ConcaveEdges.Count;

                coloroEntita(oDoc, 255, 0, 0, oEdge);

                try
                {
                    EdgeCollection oBendEdges = iApp.TransientObjects.CreateEdgeCollection();

                    oBendEdges.Add(oEdge);

                    BendDefinition oBendDef = sFeatures.BendFeatures.CreateBendDefinition(oBendEdges);

                    BendFeature oBendFeature = sFeatures.BendFeatures.Add(oBendDef);

                    //if (tmpCount != oCompDef.SurfaceBodies[1].ConcaveEdges.Count)
                    //{
                    createFillet(oDoc);
                    break;
                    //}
                }
                catch { }
            }
        }
Exemple #6
0
        /// <summary>
        ///     Removes <paramref name="vertex" /> from the graph
        /// </summary>
        /// <param name="vertex">The vertex.</param>
        /// <returns>
        ///     true if <paramref name="vertex" /> was successfully removed; otherwise falSE.
        /// </returns>
        public bool RemoveVertex(TVertex vertex)
        {
            if (!this.ContainsVertex(vertex))
            {
                return(false);
            }

            // Remove all of the edges.
            this.VertexEdges[vertex].Clear();

            // iterage over edges and remove each edge touching the vertex
            var edgeToRemove = new EdgeCollection <TVertex, TEdge>();

            foreach (var entry in this.VertexEdges)
            {
                if (entry.Key.Equals(vertex))
                {
                    continue;
                }

                foreach (var edge in entry.Value)
                {
                    if (edge.Target.Equals(vertex))
                    {
                        edgeToRemove.Add(edge);
                    }
                }
                foreach (var edge in edgeToRemove)
                {
                    entry.Value.Remove(edge);
                }
            }

            return(this.VertexEdges.Remove(vertex));
        }
Exemple #7
0
        /// <summary>
        ///     Removes all edges that match <paramref name="predicate" />.
        /// </summary>
        /// <param name="vertex">The vertex.</param>
        /// <param name="predicate">
        ///     A pure delegate that takes an
        ///     <typeparamref name="TEdge" /> and returns true if the edge should
        ///     be removed.
        /// </param>
        /// <returns>
        ///     The number of edges removed.
        /// </returns>
        /// <exception cref="System.ArgumentNullException">predicate</exception>
        public int RemoveEdge(TVertex vertex, Func <TEdge, bool> predicate)
        {
            if (!this.ContainsVertex(vertex))
            {
                return(0);
            }

            if (predicate == null)
            {
                throw new ArgumentNullException("predicate");
            }

            var edges        = this.VertexEdges[vertex];
            var edgeToRemove = new EdgeCollection <TVertex, TEdge>();

            foreach (var edge in edges)
            {
                if (predicate(edge))
                {
                    edgeToRemove.Add(edge);
                }
            }

            foreach (var edge in edgeToRemove)
            {
                edges.Remove(edge);

                if (this.EdgeList.Contains(edge))
                {
                    this.EdgeList.Remove(edge);
                }
            }

            return(edgeToRemove.Count);
        }
Exemple #8
0
        /// <summary>
        /// Remove all the out-edges of vertex u for which the predicate pred
        /// returns true.
        /// </summary>
        /// <param name="u">vertex</param>
        /// <param name="pred">edge predicate</param>
        public void RemoveOutEdgeIf(IVertex u, IEdgePredicate pred)
        {
            if (u == null)
            {
                throw new ArgumentNullException("vertex u");
            }
            if (pred == null)
            {
                throw new ArgumentNullException("predicate");
            }

            EdgeCollection edges        = VertexOutEdges[u];
            EdgeCollection removedEdges = new EdgeCollection();

            foreach (IEdge e in edges)
            {
                if (pred.Test(e))
                {
                    removedEdges.Add(e);
                }
            }

            foreach (IEdge e in removedEdges)
            {
                RemoveEdge(e);
            }
        }
        /// <summary>
        /// Augments the <see cref="VisitedGraph"/> with reversed edges.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        /// The graph has already been augmented.
        /// </exception>
        public void AddReversedEdges()
        {
            if (this.Augmented)
            {
                throw new InvalidOperationException("Graph already augmented");
            }
            // step 1, find edges that need reversing
            EdgeCollection notReversedEdges = new EdgeCollection();

            foreach (IEdge edge in this.VisitedGraph.Edges)
            {
                // if reversed already found, continue
                if (this.reversedEdges.Contains(edge))
                {
                    continue;
                }

                IEdge reversedEdge = this.FindReversedEdge(edge);
                if (reversedEdge != null)
                {
                    // setup edge
                    this.reversedEdges[edge] = reversedEdge;
                    // setup reversed if needed
                    if (!this.reversedEdges.Contains(reversedEdge))
                    {
                        this.reversedEdges[reversedEdge] = edge;
                    }
                    continue;
                }

                // this edge has no reverse
                notReversedEdges.Add(edge);
            }

            // step 2, go over each not reversed edge, add reverse
            foreach (IEdge edge in notReversedEdges)
            {
                if (this.reversedEdges.Contains(edge))
                {
                    continue;
                }

                // already been added
                IEdge reversedEdge = this.FindReversedEdge(edge);
                if (reversedEdge != null)
                {
                    this.reversedEdges[edge] = reversedEdge;
                    continue;
                }

                // need to create one
                reversedEdge = this.VisitedGraph.AddEdge(edge.Target, edge.Source);
                this.augmentedEgdes.Add(reversedEdge);
                this.reversedEdges[edge]         = reversedEdge;
                this.reversedEdges[reversedEdge] = edge;
                this.OnReservedEdgeAdded(new EdgeEventArgs(reversedEdge));
            }

            this.augmented = true;
        }
        /// <summary>
        /// Merges the temporary circuit with the current circuit
        /// </summary>
        /// <returns>true if all the graph edges are in the circuit</returns>
        protected bool CircuitAugmentation()
        {
            EdgeCollection newC = new EdgeCollection();
            int            i, j;

            // follow C until w is found
            for (i = 0; i < Circuit.Count; ++i)
            {
                IEdge e = Circuit[i];
                if (e.Source == CurrentVertex)
                {
                    break;
                }
                newC.Add(e);
            }

            // follow D until w is found again
            for (j = 0; j < TemporaryCircuit.Count; ++j)
            {
                IEdge e = TemporaryCircuit[j];
                newC.Add(e);
                OnCircuitEdge(e);
                if (e.Target == CurrentVertex)
                {
                    break;
                }
            }
            TemporaryCircuit.Clear();

            // continue C
            for (; i < Circuit.Count; ++i)
            {
                IEdge e = Circuit[i];
                newC.Add(e);
            }

            // set as new circuit
            circuit = newC;

            // check if contains all edges
            if (Circuit.Count == VisitedGraph.EdgesCount)
            {
                return(true);
            }

            return(false);
        }
Exemple #11
0
        private void CreatePart_Click(object sender, EventArgs e)
        {
            if (inventor == null)
            {
                MessageBox.Show("No inventor instance detected", "error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            PartDocument doc = inventor.Documents.Add(DocumentTypeEnum.kPartDocumentObject, null, true) as PartDocument;

            doc.PropertySets["{F29F85E0-4FF9-1068-AB91-08002B27B3D9}"]["Author"].Value = "Vladyslav Romanchuk";

            //User-defined property
            doc.PropertySets["{D5CDD505-2E9C-101B-9397-08002B2CF9AE}"].Add("Parts R Us", "Supplier");
            PartComponentDefinition partDefinition = (PartComponentDefinition)doc.ComponentDefinition;

            // Create a 2D sketch on the X-Y plane.
            PlanarSketch      sketch1 = (PlanarSketch)partDefinition.Sketches.Add(partDefinition.WorkPlanes[3]);
            TransientGeometry tg      = inventor.TransientGeometry;

            Point2d[] points = new Point2d[5] {
                tg.CreatePoint2d(0, 0), tg.CreatePoint2d(0, 20), tg.CreatePoint2d(20, 20), tg.CreatePoint2d(20, -10), tg.CreatePoint2d(10, -10)
            };
            SketchLine[] lines = new SketchLine[5];
            lines[0] = sketch1.SketchLines.AddByTwoPoints(points[0], points[1]);
            for (int i = 1; i < lines.Length - 1; i++)
            {
                lines[i] = sketch1.SketchLines.AddByTwoPoints(lines[i - 1].EndSketchPoint, points[i + 1]);
            }
            sketch1.SketchArcs.AddByCenterStartEndPoint(tg.CreatePoint2d(10, 0), lines[3].EndSketchPoint, lines[0].StartSketchPoint, false);

            //Extrude
            Profile           profile           = sketch1.Profiles.AddForSolid();
            ExtrudeDefinition extrudeDefinition = partDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kNewBodyOperation);

            extrudeDefinition.SetDistanceExtent(6, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection);
            ExtrudeFeature extrude = (ExtrudeFeature)partDefinition.Features.ExtrudeFeatures.Add(extrudeDefinition);

            //second scatch
            Face topCap = extrude.EndFaces[1];

            sketch1 = partDefinition.Sketches.Add(topCap, false);

            Point2d      center = sketch1.ModelToSketchSpace(tg.CreatePoint(2.5, 1.5, 1.5));
            SketchCircle Circle = sketch1.SketchCircles.AddByCenterRadius(center, 1);

            profile           = sketch1.Profiles.AddForSolid(true, null, null);
            extrudeDefinition = partDefinition.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kJoinOperation);
            extrudeDefinition.SetDistanceExtent(4, PartFeatureExtentDirectionEnum.kSymmetricExtentDirection);
            extrude = (ExtrudeFeature)partDefinition.Features.ExtrudeFeatures.Add(extrudeDefinition);
            Edges          cylinderEdges = extrude.SideFaces[1].Edges;
            EdgeCollection filletEdges   = inventor.TransientObjects.CreateEdgeCollection(null);

            //foreach (var el in cylinderEdges)
            //    filletEdges.Add(el);
            filletEdges.Add(cylinderEdges[2]);
            //adding fillet
            partDefinition.Features.FilletFeatures.AddSimple(filletEdges, 0.25, false, false, false, false, false, true);
            //doc.SaveAs("D:\\SaveTest2.ipt", false);
        }
 /// <summary>
 /// Processes isolated edges by computing their labelling and adding them
 /// to the isolated edges list.
 /// Isolated edges are guaranteed not to touch the boundary of the target
 /// (since if they did, they would have caused an intersection to be
 /// computed and hence would not be isolated)
 /// </summary>
 private void  LabelIsolatedEdges(int thisIndex, int targetIndex)
 {
     for (IEdgeEnumerator ei = arg[thisIndex].EdgeIterator; ei.MoveNext();)
     {
         Edge e = ei.Current;
         if (e.Isolated)
         {
             LabelIsolatedEdge(e, targetIndex, arg[targetIndex].Geometry);
             isolatedEdges.Add(e);
         }
     }
 }
Exemple #13
0
        internal override void Create_BR(TransientGeometry TG, ref PlanarSketch sketch, EdgeCollection eColl, ref Face B_face, ref Face E_face, ref PartComponentDefinition partDef)
        {
            FilletFeature fillet_Feature;

            switch (Side)
            {
            case ('r'):
                /*foreach (Edge e in B_face.Edges)
                 *  eColl.Add(e);*/
                try
                {
                    //MessageBox.Show("2 - r");
                    eColl.Add(B_face.Edges[1]);
                }
                catch
                {
                    //MessageBox.Show("1 - r");
                    eColl.Add(B_face.Edges[2]);
                }
                fillet_Feature = partDef.Features.FilletFeatures.AddSimple(eColl, Radius);
                break;

            case ('l'):
                /*foreach (Edge e in E_face.Edges)
                 *  eColl.Add(e);*/
                try
                {
                    //MessageBox.Show("2 - l");
                    eColl.Add(E_face.Edges[2]);
                }
                catch
                {
                    //MessageBox.Show("1 - l");
                    eColl.Add(E_face.Edges[1]);
                }
                fillet_Feature = partDef.Features.FilletFeatures.AddSimple(eColl, Radius);
                break;
            }
        }
        /// <summary>
        /// Remove the edge (u,v) from the graph.
        /// If the graph allows parallel edges this remove all occurrences of
        /// (u,v).
        /// </summary>
        /// <param name="u">source vertex</param>
        /// <param name="v">target vertex</param>
        public override void RemoveEdge(IVertex u, IVertex v)
        {
            if (u == null)
            {
                throw new ArgumentNullException("source vertex");
            }
            if (v == null)
            {
                throw new ArgumentNullException("targetvertex");
            }

            EdgeCollection outEdges = VertexOutEdges[u];
            EdgeCollection inEdges  = VertexInEdges[v];
            // marking edges to remove
            EdgeCollection removedEdges = new EdgeCollection();

            foreach (IEdge e in outEdges)
            {
                if (e.Target == v)
                {
                    removedEdges.Add(e);
                }
            }
            foreach (IEdge e in inEdges)
            {
                if (e.Source == u)
                {
                    removedEdges.Add(e);
                }
            }

            //removing edges
            foreach (IEdge e in removedEdges)
            {
                RemoveEdge(e);
            }
        }
Exemple #15
0
        /// <summary>
        /// Given some input EdgeCollection, iterates through its edges and adds 'valid' ones to a new
        /// collection, which is then returned.
        /// Validity is determined through the _IsLedgeValid function.
        /// </summary>
        /// <param name="ledgeColl"></param>
        /// <param name="preTileMap"></param>
        /// <param name="superTileMap"></param>
        /// <returns></returns>
        private static EdgeCollection <TileEdge> _BuildHoleGroupValidLedges(EdgeCollection <TileEdge> ledgeColl, TileMap preTileMap, TileMap superTileMap)
        {
            var validLedges = new EdgeCollection <TileEdge>();

            foreach (TileEdge ledge in ledgeColl)
            {
                if (_IsLedgeValid(ledge, preTileMap, superTileMap))
                {
                    TileEdge superimposedLedge = ledge.GetShiftedByN(SHIFT_DIST);
                    if (!validLedges.HasEdgePoints(superimposedLedge))
                    {
                        validLedges.Add(superimposedLedge);
                    }
                }
            }
            return(validLedges);
        }
        /// <summary>
        /// Simplifies the outer perim using EdgeCollections simplification algorithm.
        /// </summary>
        private Vector2[] _SimplifyOuterPerim()
        {
            var edgeCollection = new EdgeCollection <PolyEdge>();

            for (int i = 0; i < this.outerPerimNodes.Count; i++)
            {
                var thisCoord = new Vector2(this.outerPerimNodes[i].x, this.outerPerimNodes[i].y);
                var nextCoord = new Vector2(this.outerPerimNodes[(i + 1) % this.outerPerimNodes.Count].x,
                                            this.outerPerimNodes[(i + 1) % this.outerPerimNodes.Count].y);
                if (thisCoord == nextCoord)
                {
                    continue;
                }
                var polyEdge = new PolyEdge(thisCoord, nextCoord);
                edgeCollection.Add(polyEdge);
            }
            return(edgeCollection.GetSimplifiedPerim().ToArray());
        }
Exemple #17
0
        public void SetChooseEdge(QuickGraph.Concepts.IVertex v, int k, QuickGraph.Concepts.IEdge e)
        {
            if (k == 0)
            {
                this.successors.Add(v, new EdgeCollection());
            }

            EdgeCollection col = this.successors[v];

            if (col.Count <= k)
            {
                col.Add(e);
            }
            else
            {
                col[k] = e;
            }
        }
Exemple #18
0
        /// <summary>
        /// Given a single perimeter, separate it into different ledge groups as appropriate, separate its Edges
        /// into different EdgeCollections, one for each ledge group, then return both as dictionaries.
        /// </summary>
        /// <param name="ledgeCollMap">Dict which maps ledge group to EdgeCollection.</param>
        /// <param name="ledgeGroupMap">Dict which maps superimposed TileMap to ledge group.</param>
        /// The above two are here for copy-and-return purposes (maintaining object immutability).
        /// <param name="tileMaps">List of all TileMaps.</param>
        /// <param name="tileMap">TileMap that ledges are being filled for.</param>
        ///<param name="perimeter">EdgeCollection holding perimeter which will be separated in this func.</param>
        /// <param name="tileGroup">TileGroup that ledges are being filled for.</param>
        /// <param name="holeGroup">HoleGroup that ledges are being filled for.</param>
        /// <returns>Two dictionaries matching the two input dicts but with the new ledge data added to each.</returns>
        private static (Dictionary <LedgeCollKey, EdgeCollection <TileEdge> >, Dictionary <LedgeGroupKey, int>) _FillLedges(
            IDictionary <LedgeCollKey, EdgeCollection <TileEdge> > ledgeCollMap,
            IDictionary <LedgeGroupKey, int> ledgeGroupMap,
            TileMapList tileMaps,
            TileMap tileMap,
            EdgeCollection <TileEdge> perimeter,
            int tileGroup,
            int holeGroup)
        {
            var ledgeCollMapClone  = new Dictionary <LedgeCollKey, EdgeCollection <TileEdge> >(ledgeCollMap);
            var ledgeGroupMapClone = new Dictionary <LedgeGroupKey, int>(ledgeGroupMap);

            var ledges     = new EdgeCollection <TileEdge>();
            int ledgeGroup = 0;

            foreach (TileEdge edge in perimeter)
            {
                Vector2 currentTile  = edge.tileCoords;
                int     currentLayer = tileMap.ZIndex;
                Vector2 adjTile      = _GetAdjacentLowerTile(tileMaps, edge, currentLayer);

                if (adjTile == currentTile)
                { //no adjacent tile exists
                    ledges.Add(edge);
                }
                else if (ledges.Count > 0)
                { //gap in ledges, finish current ledge group and move to next one
                    ledgeCollMapClone.Add(new LedgeCollKey(tileMap, tileGroup, holeGroup, tileMap, ledgeGroup),
                                          new EdgeCollection <TileEdge>(ledges.GetOrderedCollection()));
                    ledgeGroup++;
                    ledges = new EdgeCollection <TileEdge>();
                }
            }

            if (ledges.Count > 0)
            { //store ledges if not done already
                ledgeCollMapClone.Add(new LedgeCollKey(tileMap, tileGroup, holeGroup, tileMap, ledgeGroup),
                                      new EdgeCollection <TileEdge>(ledges.GetOrderedCollection()));
                ledgeGroup++;
            }

            ledgeGroupMapClone.Add(new LedgeGroupKey(tileMap, tileGroup, holeGroup, tileMap), ledgeGroup);
            return(ledgeCollMapClone, ledgeGroupMapClone);
        }
Exemple #19
0
		/// <summary> 
		/// If edges which have undergone dimensional collapse are found,
		/// replace them with a new edge which is a L edge
		/// </summary>
		private void ReplaceCollapsedEdges()
		{
            EdgeCollection replacableEdges = new EdgeCollection();

			for (IEdgeEnumerator it = edgeList.Iterator(); it.MoveNext();)
			{
				Edge e = it.Current;
				if (e.IsCollapsed)
				{
                    replacableEdges.Add(e);
				}
			}

            int nCount = replacableEdges.Count;
            for (int i = 0; i < nCount; i++)
            {
                Edge e = replacableEdges[i];
                edgeList.Replace(e, e.CollapsedEdge);
            }
		}
Exemple #20
0
        private void Node_MouseUp(object sender, MouseEventArgs e)
        {
            if (_ball != null && _ball.IsRunning)
            {
                return;
            }
            Node ctl = (Node)sender;

            if (e.Button == MouseButtons.Left)
            {
                if (this.Tool == DrawingTools.Edge)
                {
                    Point p2   = this.PointToClient(ctl.PointToScreen(e.Location));
                    Node  node = this.GetChildAtPoint(p2) as Node;
                    if (node != null)
                    {
                        _edges.Add(new Edge(_startIndex, node.Index));
                    }
                }
                Invalidate();
                OnContentChanged(null, null);
            }
        }
        public static List <Lavorazione> main(EdgeLoops oEdgeLoops, Inventor.Application iApp)
        {
            List <Lavorazione> result = new List <Lavorazione>();

            foreach (EdgeLoop oEdgeLoop in oEdgeLoops)
            {
                string nameLav = whois(oEdgeLoop.Edges);

                if (!string.IsNullOrEmpty(nameLav))
                {
                    EdgeCollection oEdgeColl = iApp.TransientObjects.CreateEdgeCollection();

                    foreach (Edge oEdge in oEdgeLoop.Edges)
                    {
                        oEdgeColl.Add(oEdge);
                    }

                    result.Add(new Lavorazione(nameLav, oEdgeColl));
                }
            }

            return(result);
        }
Exemple #22
0
        /// <summary>
        /// Remove all the edges from graph g for which the predicate pred
        /// returns true.
        /// </summary>
        /// <param name="pred">edge predicate</param>
        public void RemoveEdgeIf(IEdgePredicate pred)
        {
            if (pred == null)
            {
                throw new ArgumentNullException("predicate");
            }

            // marking edge for removal
            EdgeCollection removedEdges = new EdgeCollection();

            foreach (IEdge e in Edges)
            {
                if (pred.Test(e))
                {
                    removedEdges.Add(e);
                }
            }

            // removing edges
            foreach (IEdge e in removedEdges)
            {
                RemoveEdge(e);
            }
        }
Exemple #23
0
 public void AddEdge(string node1, string node2)
 {
     EdgeCollection.Add(new Edge {
         EDG_NODE1 = node1, EDG_NODE2 = node2, EDG_LENGTH = 1, EDG_WEIGTH = 1
     });
 }
Exemple #24
0
 public void AddEdge(string node1, string node2, int length, int weigth)
 {
     EdgeCollection.Add(new Edge {
         EDG_NODE1 = node1, EDG_NODE2 = node2, EDG_LENGTH = length, EDG_WEIGTH = weigth
     });
 }
        /// <summary>
        /// Computes a set of eulerian trail, starting at <paramref name="s"/>
        /// that spans the entire graph.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method computes a set of eulerian trail starting at <paramref name="s"/>
        /// that spans the entire graph.The algorithm outline is as follows:
        /// </para>
        /// <para>
        /// The algorithms iterates throught the Eulerian circuit of the augmented
        /// graph (the augmented graph is the graph with additional edges to make
        /// the number of odd vertices even).
        /// </para>
        /// <para>
        /// If the current edge is not temporary, it is added to the current trail.
        /// </para>
        /// <para>
        /// If the current edge is temporary, the current trail is finished and
        /// added to the trail collection. The shortest path between the
        /// start vertex <paramref name="s"/> and the target vertex of the
        /// temporary edge is then used to start the new trail. This shortest
        /// path is computed using the <see cref="BreadthFirstSearchAlgorithm"/>.
        /// </para>
        /// </remarks>
        /// <param name="s">start vertex</param>
        /// <returns>eulerian trail set, all starting at s</returns>
        /// <exception cref="ArgumentNullException">s is a null reference.</exception>
        /// <exception cref="Exception">Eulerian trail not computed yet.</exception>
        public EdgeCollectionCollection Trails(IVertex s)
        {
            if (s == null)
            {
                throw new ArgumentNullException("s");
            }
            if (this.Circuit.Count == 0)
            {
                throw new Exception("Circuit is empty");
            }

            // find the first edge in the circuit.
            int i = 0;

            for (i = 0; i < this.Circuit.Count; ++i)
            {
                IEdge e = this.Circuit[i];
                if (TemporaryEdges.Contains(e))
                {
                    continue;
                }
                if (e.Source == s)
                {
                    break;
                }
            }
            if (i == this.Circuit.Count)
            {
                throw new Exception("Did not find vertex in eulerian trail?");
            }

            // create collections
            EdgeCollectionCollection    trails = new EdgeCollectionCollection();
            EdgeCollection              trail  = new EdgeCollection();
            BreadthFirstSearchAlgorithm bfs    =
                new BreadthFirstSearchAlgorithm(VisitedGraph);
            PredecessorRecorderVisitor vis = new PredecessorRecorderVisitor();

            bfs.RegisterPredecessorRecorderHandlers(vis);
            bfs.Compute(s);

            // go throught the edges and build the predecessor table.
            int start = i;

            for (; i < this.Circuit.Count; ++i)
            {
                IEdge e = this.Circuit[i];
                if (TemporaryEdges.Contains(e))
                {
                    // store previous trail and start new one.
                    if (trail.Count != 0)
                    {
                        trails.Add(trail);
                    }
                    // start new trail
                    // take the shortest path from the start vertex to
                    // the target vertex
                    trail = vis.Path(e.Target);
                }
                else
                {
                    trail.Add(e);
                }
            }

            // starting again on the circuit
            for (i = 0; i < start; ++i)
            {
                IEdge e = this.Circuit[i];
                if (TemporaryEdges.Contains(e))
                {
                    // store previous trail and start new one.
                    if (trail.Count != 0)
                    {
                        trails.Add(trail);
                    }
                    // start new trail
                    // take the shortest path from the start vertex to
                    // the target vertex
                    trail = vis.Path(e.Target);
                }
                else
                {
                    trail.Add(e);
                }
            }

            // adding the last element
            if (trail.Count != 0)
            {
                trails.Add(trail);
            }

            return(trails);
        }
Exemple #26
0
        private void ButtonBuild_Click(object sender, EventArgs e)
        {
            if (FalseWrite)
            {
                MessageBox.Show("Неправильно заданы входные параметры\nИсправьте красные поля");
                return;
            }

            string docName = "Первая деталь";

            CreateDoc(docName);

            // Создание эскиза на YX
            PlanarSketch Sketch = CompDef[docName].Sketches.Add(CompDef[docName].WorkPlanes[3]);    // 1 - YZ ; 2 - ZX; 3 - XY

            // Создание массивов Точек, Линий, Дуг, Окружностей
            List <SketchPoint>  points  = new List <SketchPoint>();  // Точки
            List <SketchLine>   lines   = new List <SketchLine>();   // Линии
            List <SketchArc>    arcs    = new List <SketchArc>();    // Дуги
            List <SketchCircle> circles = new List <SketchCircle>(); // Окружности

            /////////////////////////////////////////////////////////// Выдавливание

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 0), false));
            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 5.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 10.0 / 10), false));
            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 15.0 / 10), false));
            arcs.Add(Sketch.SketchArcs.AddByCenterStartEndPoint(points[points.Count - 2], points[points.Count - 3], points[points.Count - 1], true));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 20.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(20.0 / 10, 20.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(20.0 / 10, 0), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[0], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(10.0 / 10, 10.0 / 10), false));
            circles.Add(Sketch.SketchCircles.AddByCenterRadius(points[points.Count - 1], 4.0 / 10));

            Profile ProfileMain = (Profile)Sketch.Profiles.AddForSolid();

            ExtrudeFeature ExtrudeDef = CompDef[docName].Features.ExtrudeFeatures.AddByDistanceExtent(
                /*Эскиз*/ ProfileMain,
                /*Длина в см*/ 10.0 / 10,
                /*Направление вдоль оси*/ PartFeatureExtentDirectionEnum.kPositiveExtentDirection,
                /*Операция*/ PartFeatureOperationEnum.kJoinOperation,
                /*Эскиз*/ ProfileMain);

            /////////////////////////////////////////////////////////// Вращение

            WorkPlane WorkinPlace = CompDef[docName].WorkPlanes.AddByPlaneAndOffset(
                CompDef[docName].WorkPlanes[2], 20.0 / 10);

            WorkinPlace.Visible = false;
            Sketch = CompDef[docName].Sketches.Add(WorkinPlace);

            SketchLine line_axis;

            points.Clear();
            lines.Clear();

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-(10.0 - 5) / 10, 0), false));
            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-(10.0 - 5) / 10, 10.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-10.0 / 10, 10.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-10.0 / 10, 0), false));
            line_axis = Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]);

            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[0], points[points.Count - 1]));

            Profile        ProfileExternal = (Profile)Sketch.Profiles.AddForSolid();
            RevolveFeature revolvefeature  = CompDef[docName].Features.RevolveFeatures.AddFull(
                ProfileExternal,
                line_axis,
                PartFeatureOperationEnum.kCutOperation);

            Trans[docName].End();

            /////////////////////////////////////////////////////////// Вторая деталь

            docName = "Вторая деталь";
            CreateDoc(docName);

            Sketch = CompDef[docName].Sketches.Add(CompDef[docName].WorkPlanes[3]);

            points.Clear();
            lines.Clear();

            ///////////////////////////////////////////////// Шестиугольник

            double R = 2 * (4.0 / 10) / Math.Sqrt(3), Angle;

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(
                                                   1.65 * Math.Cos(((double)210 / 180) * Math.PI),
                                                   1.65 * Math.Sin(((double)210 / 180) * Math.PI)), true));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(points[0].Geometry.X + R, points[0].Geometry.Y), true));
            for (int i = 2; i < 7; i++)
            {
                Angle = ((((double)i - 2) * 60 + 120) / 180);
                points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(
                                                       points[i - 1].Geometry.X + R * Math.Cos(Angle * Math.PI),
                                                       points[i - 1].Geometry.Y + R * Math.Sin(Angle * Math.PI)), true));

                lines.Add(Sketch.SketchLines.AddByTwoPoints(points[i - 1], points[i]));
            }
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[6], points[1]));

            ProfileMain = (Profile)Sketch.Profiles.AddForSolid();

            ExtrudeDef = CompDef[docName].Features.ExtrudeFeatures.AddByDistanceExtent(
                /*Эскиз*/ ProfileMain,
                /*Длина*/ 10.0 / 10,
                /*Направление вдоль оси*/ PartFeatureExtentDirectionEnum.kPositiveExtentDirection,
                /*Операция*/ PartFeatureOperationEnum.kJoinOperation,
                /*Эскиз*/ ProfileMain);

            ///////////////////////////////////////////////// Фаска
            ChamferFeature Fillet;

            EdgeCollection Edges = ThisApplication.TransientObjects.CreateEdgeCollection();

            int k = 0;

            foreach (SurfaceBody SurfBody in PartDoc[docName].ComponentDefinition.SurfaceBodies)
            {
                foreach (Edge Edge in SurfBody.Edges)
                {
                    if (k == 2)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 5)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 8)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 11)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 14)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 17)
                    {
                        Edges.Add(Edge);
                    }
                    k++;
                }
            }

            Fillet = CompDef[docName].Features.ChamferFeatures.AddUsingDistance(Edges, 2.0 / 10);

            ///////////////////////////////////////////////// СОПРЯЖЕНИЕ
            FilletFeature Fillet1;

            Edges.Clear();

            int n = 0;

            foreach (SurfaceBody SurfBody in PartDoc[docName].ComponentDefinition.SurfaceBodies)
            {
                foreach (Edge Edge in SurfBody.Edges)
                {
                    if (n == 18)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 20)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 21)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 23)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 26)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 27)
                    {
                        Edges.Add(Edge);
                    }

                    n++;
                }
            }

            Fillet1 = CompDef[docName].Features.FilletFeatures.AddSimple(Edges, /*Радиус*/ 1.0 / 10);

            // Заврешение транзакции
            Trans[docName].End();
        }
        /// <summary>
        /// Adds temporary edges to the graph to make all vertex even.
        /// </summary>
        /// <param name="g"></param>
        /// <returns></returns>
        public EdgeCollection AddTemporaryEdges(IMutableVertexAndEdgeListGraph g)
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }

            // first gather odd edges.
            VertexCollection oddVertices = AlgoUtility.OddVertices(g);

            // check that there are an even number of them
            if (oddVertices.Count % 2 != 0)
            {
                throw new Exception("number of odd vertices in not even!");
            }

            // add temporary edges to create even edges:
            EdgeCollection ec = new EdgeCollection();

            bool found, foundbe, foundadjacent;

            while (oddVertices.Count > 0)
            {
                IVertex u = oddVertices[0];
                // find adjacent odd vertex.
                found         = false;
                foundadjacent = false;
                foreach (IEdge e in g.OutEdges(u))
                {
                    IVertex v = e.Target;
                    if (v != u && oddVertices.Contains(v))
                    {
                        foundadjacent = true;
                        // check that v does not have an out-edge towards u
                        foundbe = false;
                        foreach (IEdge be in g.OutEdges(v))
                        {
                            if (be.Target == u)
                            {
                                foundbe = true;
                                break;
                            }
                        }
                        if (foundbe)
                        {
                            continue;
                        }
                        // add temporary edge
                        IEdge tempEdge = g.AddEdge(v, u);
                        // add to collection
                        ec.Add(tempEdge);
                        // remove u,v from oddVertices
                        oddVertices.Remove(u);
                        oddVertices.Remove(v);
                        // set u to null
                        found = true;
                        break;
                    }
                }

                if (!foundadjacent)
                {
                    // pick another vertex
                    if (oddVertices.Count < 2)
                    {
                        throw new Exception("Eulerian trail failure");
                    }
                    IVertex v        = oddVertices[1];
                    IEdge   tempEdge = g.AddEdge(u, v);
                    // add to collection
                    ec.Add(tempEdge);
                    // remove u,v from oddVertices
                    oddVertices.Remove(u);
                    oddVertices.Remove(v);
                    // set u to null
                    found = true;
                }

                if (!found)
                {
                    oddVertices.Remove(u);
                    oddVertices.Add(u);
                }
            }

            temporaryEdges = ec;

            return(ec);
        }