public void AllocDeallocSimpleTest() { //NaroMessage.Show("start test"); //Console.WriteLine("---- wrapper start test ----"); var watch = new Stopwatch(); watch.Start(); for (var i = 0; i < 300000; i++) { var pnt = new gpPnt(i, i, i); var pnt2 = new gpPnt(i + 10, i + 10, i + 10); var aEdge = new BRepBuilderAPIMakeEdge(pnt, pnt2).Edge; var wire = new BRepBuilderAPIMakeWire(aEdge).Wire; TopoDSShape shape = wire; new AISShape(shape); var pln = new gpPln(i + 10, i + 10, i + 10, i + 10); var geomPln = new GeomPlane(pln); var trsf = new gpTrsf(); geomPln.Transform(trsf); } watch.Stop(); //Console.WriteLine("---- wrapper end test - took {0} ms ----", watch.ElapsedMilliseconds); //NaroMessage.Show(String.Format("---- wrapper end test - took {0} ms ----", watch.ElapsedMilliseconds)); }
private void ProposeSelectedReferenceShape(TopoDSShape face, Mouse3DPosition mouseData) { SceneSelectedEntity selectedNode = null; if (face != null) { selectedNode = GeomUtils.IdentifyNode(Document.Root, face); if (selectedNode == null) { return; } } else { var node = NodeBuilderUtils.IdentifySelectedObjectLabel(Document.Root); if (node != null) { selectedNode = new SceneSelectedEntity(node); } } if (selectedNode == null) { return; } if (_axisBuilder.Node != null && selectedNode.Node.Index == _axisBuilder.Node.Index) { SetWorkingPlane(); _dragging = true; _startDragPos = mouseData.Point; return; } // The scene selected entity is hold as reference Propose(selectedNode); }
public static void LoadBrepFile(string fileName, Document document) { var aSequence = new TopToolsHSequenceOfShape(); var aShape = new TopoDSShape(); var aBuilder = new BRepBuilder(); var result = BRepTools.Read(aShape, fileName, aBuilder, null); if (result) { if (!BRepAlgo.IsValid(aShape)) { // Warning: The shape is not valid! } else { aSequence.Append(aShape); } } if (aSequence.IsEmpty) { return; } document.Transact(); for (var i = 1; i <= aSequence.Length; i++) { var aisShape = aSequence.Value(i); var builder = new NodeBuilder(document, FunctionNames.Mesh); builder[0].Shape = aisShape; builder.ExecuteFunction(); } document.Commit("Added to scene filename: " + fileName); }
public static ShapeBoundBox ExtractBoundingBox(TopoDSShape topoDsShape) { if (topoDsShape == null) { return(null); } var bndBox = ExtractBndBox(topoDsShape); if (bndBox == null) { return(null); } var aXMin = 0d; var aYMin = 0d; var aZMin = 0d; var aXMax = 0d; var aYMax = 0d; var aZMax = 0d; bndBox.Get(ref aXMin, ref aYMin, ref aZMin, ref aXMax, ref aYMax, ref aZMax); var coordinate = new Point3D(aXMin, aYMin, aZMin); var dimensions = new Point3D(aXMax - aXMin, aYMax - aYMin, aZMax - aZMin); var result = new ShapeBoundBox { Coordinate = coordinate, Dimensions = dimensions }; return(result); }
/// <summary> /// Called when the dragging operation ends. /// </summary> public virtual void EndDragging(Mouse3DPosition mouseData) { if (IsDragging) { prevFaceCount = -1; IsDragging = false; Document.Commit("Finished dragging"); selectedShape = null; } }
public void StartDragging(SceneSelectedEntity handleNode) { IsDragging = true; if (SelectedEntity.ShapeType == TopAbsShapeEnum.TopAbs_FACE) { selectedShape = SelectedEntity.TargetShape(); prevFaceCount = -1; initialDirection = GeomUtils.ExtractDirection(SelectedEntity.TargetShape()); DraggingIndex = 0;// _handles[FunctionNames.AxisHandle]; } }
private static TopoDSShape MakeSew(TopoDSShape path, TopoDSShape profile) { var sewing = new BRepBuilderAPISewing(1.0e-06, true, true, true, false); sewing.Add(profile); sewing.Add(path); MessageProgressIndicator messg = new MessageProgressIndicator(); sewing.Perform(messg); return(sewing.SewedShape); }
public static gpPln ExtractPlaneFromFaceShape(TopoDSShape targetFace) { var face = TopoDS.Face(targetFace); var surf = BRepTool.Surface(face); var pl = new GeomPlane(new gpAx3()); pl = surf.Convert <GeomPlane>(); //surf.DownCast(ref pl); var faceElementAdaptor = new BRepAdaptorSurface(face, true); //TO DO: Investigate why this is not working Ensure.AreEqual(faceElementAdaptor.GetType, GeomAbsSurfaceType.GeomAbs_Plane); return(pl.Pln); }
public static BndBox ExtractBndBox(TopoDSShape topoDsShape) { var shape = new AISShape(topoDsShape); try { var bndBox = shape.BoundingBox; return(bndBox); } catch { return(null); } }
public static AISInteractiveObject TextureShape(TopoDSShape shape, string texture, Node node) { var texturedShape = new AISTexturedShape(shape); var textNameWrapper = new TCollectionAsciiString(texture); node.Set <ObjectInterpreter>().Data = textNameWrapper; texturedShape.TextureFileName = textNameWrapper; texturedShape.SetTextureMapOn(); texturedShape.SetTextureRepeat(false, 1.0, 1.0); texturedShape.DisplayMode = 3; texturedShape.SetColor(ShapeUtils.GetOccColor(Color.White)); texturedShape.TypeOfPresentation = (PrsMgrTypeOfPresentation3d.PrsMgr_TOP_AllView); return(texturedShape); }
/// <summary> /// Make an extrusion starting from a shape until a height. /// </summary> /// <param name = "originalShape"></param> /// <param name = "height"></param> /// <returns></returns> private static TopoDSShape ExtrudeMidPlane(TopoDSShape originalShape, double height) { TopoDSShape prismShape = null; // Make the Extrusion if (originalShape != null) { try { // Get the Face to be extruded var face = originalShape;// OCTopoDS.Face(originalShape); // Get the direction var dir = GeomUtils.ExtractDirection(face); if (dir == null) { return(null); } // Build the translated shape var translationVector = new gpVec(dir); translationVector.Multiply(-1 * height / 2); var transformation = new gpTrsf(); transformation.SetTranslation(translationVector); var brepTrans = new BRepBuilderAPITransform(originalShape, transformation, false); var translatedShape = brepTrans.Shape; // Extract the face of the translated shape //baseEx.Init(translatedShape, TopAbsShapeEnum.TopAbs_FACE, TopAbsShapeEnum.TopAbs_SHAPE); //baseEx.Next(); var translatedFace = translatedShape;// OCTopoDS.Face(translatedShape); // Describe the height through a vector var vector = new gpVec(dir); vector.Multiply(height); // Make the prism prismShape = new BRepPrimAPIMakePrism(translatedFace, vector, false, true).Shape; } catch (Exception ex) { Log.Error("Error on extrude: " + ex.Message); return(null); } } return(prismShape); }
public static TopoDSShape ExtractSubShape( TopoDSShape originalShape, int facePosition, TopAbsShapeEnum shapeType) { if (originalShape == null) { return(null); } // Find the face var baseEx = new TopExpExplorer(); baseEx.Init(originalShape, shapeType, TopAbsShapeEnum.TopAbs_SHAPE); while (baseEx.More && (facePosition != 1)) { baseEx.Next(); facePosition--; } //if (!baseEx.More()) // return null; TopoDSShape shape = null; switch (shapeType) { case TopAbsShapeEnum.TopAbs_VERTEX: shape = TopoDS.Vertex(baseEx.Current); break; case TopAbsShapeEnum.TopAbs_EDGE: shape = TopoDS.Edge(baseEx.Current); break; case TopAbsShapeEnum.TopAbs_WIRE: shape = TopoDS.Wire(baseEx.Current); break; case TopAbsShapeEnum.TopAbs_FACE: shape = TopoDS.Face(baseEx.Current); break; case TopAbsShapeEnum.TopAbs_SOLID: case TopAbsShapeEnum.TopAbs_COMPOUND: return(originalShape); } return(shape); }
/// <summary> /// 0 - Shapes have no common edges /// 1 - Shapes have some edges in common /// 2 - Shape1 is inside the other /// 3 - Shape2 is inside the other /// </summary> /// <param name="shape1"></param> /// <param name="shape2"></param> /// <returns></returns> private static int RelativePosition(TopoDSShape shape1, TopoDSShape shape2) { var edgesShape1 = GeomUtils.ExtractEdges(shape1); var edgesShape2 = GeomUtils.ExtractEdges(shape2); if (edgesShape1.Count == 1 || edgesShape2.Count == 1) { var position = ShapeIsInsideShape(shape1, shape2); if (position == 1) { return(2); } if (position == 2) { return(3); } } int commonEdgesCount = 0; for (int i = 0; i < edgesShape1.Count; i++) { bool found = false; for (int j = 0; j < edgesShape2.Count && !found; j++) { if (EdgesAreIdentical(edgesShape1[i], edgesShape2[j])) { commonEdgesCount++; found = true; } } } if (commonEdgesCount == edgesShape1.Count) { return(2); } if (commonEdgesCount == edgesShape2.Count) { return(3); } if (commonEdgesCount > 0) { return(1); } return(0); }