//-------------------------------------------------------------------------------------------------- protected override bool MakeInternal(MakeFlags flags) { ClearSubshapeLists(); var context = new MakeContext(); if (!_DoInitContext(context)) { return(false); } if (!_DoBuildWireList(context)) { return(false); } if (!_DoThruSections(context)) { return(false); } if (!_DoThicken(context)) { return(false); } BRep = context.Result; return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- protected override bool MakeInternal(MakeFlags flags) { ClearSubshapeLists(); var context = new MakeContext(); if (!_DoInitContext(context)) { return(false); } if (!_DoComputeArguments(context)) { return(false); } _DoOffset(context); // Offset can fail if (!_DoDraft(context)) { return(false); } BRep = context.Result; return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- #endregion #region Make protected override bool MakeInternal(MakeFlags flags) { if (Operands.Count < 2) { Messages.Error("Linked body is lost."); return(false); } switch (Operands[1]) { case BodyShapeOperand bodyOp: BRep = bodyOp?.Shape?.GetBRep(); if (BRep == null) { Messages.Error("Linked body is invalid."); return(false); } break; case Shape shape: BRep = shape.GetBRep(); if (BRep == null) { Messages.Error("Linked Shape has no valid geometry."); return(false); } break; default: Messages.Error("Referenced type not supported."); break; } return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- #endregion #region Make protected override bool MakeInternal(MakeFlags flags) { ClearSubshapeLists(); // We take only one source shape if (Operands.Count != 1) { Messages.Error("This modifier needs exactly one source shape."); return(false); } switch (GetOperand(0).GetShapeType()) { case ShapeType.Sketch: if (!_MakeSketch()) { return(false); } break; case ShapeType.Solid: if (!_MakeSolid()) { return(false); } break; default: Messages.Error("The shape type of the preceeding shape is not supported."); break; } return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- #endregion #region Make protected override bool MakeInternal(MakeFlags flags) { ClearSubshapeLists(); // Currently we work with 1 source shape only if (Operands.Count != 1) { Messages.Error("Extrude needs exactly one source shape."); return(false); } bool result = false; switch (GetOperand(0).GetShapeType()) { case ShapeType.Sketch: result = _Make2D(); break; case ShapeType.Solid: result = _Make3D(); break; } return(result && base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- #endregion #region Make protected override bool MakeInternal(MakeFlags flags) { var makeCylinder = ((SegmentAngle <= 0) || (SegmentAngle >= 360)) ? new BRepPrimAPI_MakeCylinder(Radius, Height) : new BRepPrimAPI_MakeCylinder(Radius, Height, SegmentAngle.Clamp(0.001, 360.0).ToRad()); BRep = makeCylinder.Solid(); return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- protected virtual bool MakeInternal(MakeFlags flags) { if (BRep != null) { if (!flags.HasFlag(MakeFlags.NoTransformation)) { TransformedBRep = BRep.Moved(new TopLoc_Location(GetTransformation())); } return(true); } return(false); }
//-------------------------------------------------------------------------------------------------- protected override bool MakeInternal(MakeFlags flags) { ClearSubshapeLists(); // Currently we work with 1 source shape only if (Operands.Count != 1 || _Face == null) { return(false); } // Get Targets var context = new MakeContext { TargetShape = GetOperandBRep(0), TargetFace = GetOperandFace(0, Face) }; // Check targets if (context.TargetShape == null) { return(false); } if (context.TargetFace == null) { Messages.Error("Face for adding flange cannot be found in shape and needs to be reselected."); return(false); } // Skip if we have nothing to do if (_Angle == 0 && _Length <= 0) { return(Skip()); } // Make it! if (!(_FindBendAxis(context) && _MakeFlangeFace(context) && _MakeBendSection(context) && _MakeFlangeSection(context) && _BuildResult(context))) { return(false); } if (context.ResultShape == null) { return(Skip()); } BRep = context.ResultShape; return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- protected override bool MakeInternal(MakeFlags flags) { ClearSubshapeLists(); // Check if connection is valid if (AssociatedShape == null) { return(Skip()); } var context = new MakeContext(); if (!_DoInitContext(context)) { return(false); } // Build common Solid if (!_DoMakeCommon(context)) { return(false); } // Nothing in Common if (context.Common == null) { return(Skip()); } // Create box pieces if (!_DoCreateBoxes(context)) { return(false); } // Cutoff Excess if (_RemoveExcess && !_DoCutoffExcess(context)) { return(false); } // Cut box pieces out of the shape if (!_DoCutoutBoxes(context)) { return(false); } BRep = context.Result; return(base.MakeInternal(flags)); }
/////////////////////////////////////////////////////////////////////// public static bool HasFlags( MakeFlags flags, MakeFlags hasFlags, bool all ) { if (all) { return((flags & hasFlags) == hasFlags); } else { return((flags & hasFlags) != MakeFlags.None); } }
//-------------------------------------------------------------------------------------------------- #endregion #region Make protected override bool MakeInternal(MakeFlags flags = MakeFlags.None) { ClearSubshapeLists(); ContourEdges.Clear(); if (Operands.Count < 1) { Messages.Error("Fillet needs at least one operand shape."); return(false); } var sourceShape = GetOperandBRep(0); if (sourceShape == null) { return(false); } // If no edges are selected, just copy the source shape if (Edges.Length == 0) { return(Skip()); } var makeFillet = new BRepFilletAPI_MakeFillet(sourceShape, ChFi3d_FilletShape.ChFi3d_Rational); // Select edges var edges = GetOcEdges().ToArray(); if (!edges.Any()) { Messages.Error("Edges no longer found. You need to reselect edges to fillet."); return(false); } foreach (var edge in edges) { makeFillet.Add(Radius, edge); } // Get final shape BRep = makeFillet.Shape(); UpdateModifiedSubshapes(sourceShape, makeFillet); UpdateContourEdges(makeFillet, edges); return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- public bool Make(MakeFlags flags) { try { CoreContext.Current.MessageHandler.ClearEntityMessages(this); if (_IsSkipped) { if (Skip()) { return(true); } } using (new ProcessingScope(this, "Making Shape")) { if (IsValid) { Invalidate(); } if (MakeInternal(flags)) { HasErrors = false; _IsLoadedFromCache = false; return(true); } Messages.Error("Shape making failed."); } } catch (SEHException e) { // Try to get infos from native var info = Interop.ExceptionHelper.GetNativeExceptionInfo(Marshal.GetExceptionPointers()); Messages.Exception(info != null ? $"Modeling Exception - {info.Message}" : "Exception while making shape.", e, this); Console.WriteLine(e); } catch (Exception e) { Messages.Exception("Exception while making shape.", e, this); Console.WriteLine(e); } HasErrors = true; return(false); }
//-------------------------------------------------------------------------------------------------- #endregion #region Make protected override bool MakeInternal(MakeFlags flags) { ClearSubshapeLists(); // Currently we work with 1 source shape only if (Operands.Count != 1) { Messages.Error("This modifier needs exactly one source shape."); return(false); } // We work with 2D shapes as source var sourceShape = GetOperand(0); switch (sourceShape.GetShapeType()) { case ShapeType.Sketch: if (!_MakeSketch(sourceShape)) { return(false); } break; case ShapeType.Solid: if (!_MakeSolid(sourceShape)) { return(false); } break; default: Messages.Error("This modifier needs a sketch or solid as source shape."); return(false); } return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- protected override bool MakeInternal(MakeFlags flags) { if (_CachedOcShape == null) { if ((Data == null) || (Data.Length == 0)) { Messages.Error("The data of this mesh is empty or invalid."); HasErrors = true; return(false); } _CachedOcShape = Occt.Helper.BRepExchange.ReadBinary(Data); if (_CachedOcShape == null) { Messages.Error("The mesh could not be reconstructed."); HasErrors = true; return(false); } } BRep = _CachedOcShape; return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- protected override bool MakeInternal(MakeFlags flags) { ClearSubshapeLists(); // Make it! var context = new MakeContext { DebugOutput = flags.HasFlag(MakeFlags.DebugOutput) }; if (!(_InitContext(context) && _AnalyzeTopology(context))) { return(false); } // Skip if we have only one section if (!context.RootSection.Children.Any()) { return(Skip()); } if (!_BuildResultShape(context)) { return(false); } if (context.ResultShape == null) { return(Skip()); } BRep = context.ResultShape; return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- protected override bool MakeInternal(MakeFlags flags) { if (!Segments.Any() || !Points.Any()) { var makeVertex = new BRepBuilderAPI_MakeVertex(Pnt.Origin); BRep = makeVertex.Vertex(); HasErrors = false; return(base.MakeInternal(flags)); } // Create edges var freeSegmentEdges = new Dictionary <SketchSegment, TopoDS_Edge>(); foreach (var segmentKvp in _Segments) { var segment = segmentKvp.Value; if (segment.IsAuxilliary) { continue; } var segEdge = segment.MakeEdge(_Points); if (segEdge == null) { Messages.Warning($"The segment {segmentKvp.Key} of type {segment.GetType().Name} failed creating an edge."); continue; } freeSegmentEdges.Add(segment, segEdge); AddNamedSubshape("seg", segEdge, segmentKvp.Key); } // Create wires var wires = new List <TopoDS_Wire>(); while (freeSegmentEdges.Any()) { var nextSegmentEdge = freeSegmentEdges.First(); var frontSegment = nextSegmentEdge.Key; freeSegmentEdges.Remove(nextSegmentEdge.Key); var makeWire = new BRepBuilderAPI_MakeWire(nextSegmentEdge.Value); if ((frontSegment.StartPoint != -1) || (frontSegment.EndPoint != -1)) { var backSegment = frontSegment; while (freeSegmentEdges.Any()) { nextSegmentEdge = freeSegmentEdges.FirstOrDefault(kvp => kvp.Key.IsConnected(frontSegment)); if (nextSegmentEdge.Value != null) { frontSegment = nextSegmentEdge.Key; } else { nextSegmentEdge = freeSegmentEdges.FirstOrDefault(kvp => kvp.Key.IsConnected(backSegment)); if (nextSegmentEdge.Value != null) { backSegment = nextSegmentEdge.Key; } else { // disconnected segment break; } } makeWire.Add(nextSegmentEdge.Value); freeSegmentEdges.Remove(nextSegmentEdge.Key); } } // Get wire shape var wire = makeWire.Wire(); if (wire == null) { Messages.Error("Error when creating a wire."); return(false); } wires.Add(wire); } // Create resulting shape var builder = new TopoDS_Builder(); var shape = new TopoDS_Compound(); builder.MakeCompound(shape); foreach (var wire in wires) { builder.Add(shape, wire); } BRep = shape; return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- #endregion #region Make protected override bool MakeInternal(MakeFlags flags) { double?segAngle = null; if (SegmentAngle > 0) { segAngle = SegmentAngle.Clamp(0, 360); } double?topAngle = null; if (MaxLatitude < 90) { topAngle = MaxLatitude.Clamp(-90, 90); } double?bottomAngle = null; if (MinLatitude > -90) { bottomAngle = MinLatitude.Clamp(-90, 90); } bool useLatitudeExtents = (topAngle.HasValue || bottomAngle.HasValue); if (useLatitudeExtents) { if (!topAngle.HasValue) { topAngle = 90; } if (!bottomAngle.HasValue) { bottomAngle = -90; } if (topAngle.Value <= bottomAngle.Value) { return(false); } } BRepPrimAPI_MakeSphere makeSphere; if (segAngle.HasValue) { if (useLatitudeExtents) { makeSphere = new BRepPrimAPI_MakeSphere(Radius, bottomAngle.Value.ToRad(), topAngle.Value.ToRad(), segAngle.Value.ToRad()); } else { makeSphere = new BRepPrimAPI_MakeSphere(Radius, segAngle.Value.ToRad()); } } else { if (useLatitudeExtents) { makeSphere = new BRepPrimAPI_MakeSphere(Radius, bottomAngle.Value.ToRad(), topAngle.Value.ToRad()); } else { makeSphere = new BRepPrimAPI_MakeSphere(Radius); } } BRep = makeSphere.Solid(); return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- protected override bool MakeInternal(MakeFlags flags) { // Currently we work with 1 source shape only if (Operands.Count != 1) { Messages.Error("Revolve needs exactly one source shape."); HasErrors = true; return(false); } // We work with 2D shapes as source var faceShape = GetOperand2DFaces(0, null); if (faceShape == null) { return(false); } // If the shape is empty, just copy the source shape if (faceShape.Faces().Count == 0) { Messages.Error("The sketch does not contain any valid contours."); return(false); } // Get axis var axis = ComputeAxis(); if (axis == null) { Messages.Error("The revolving axis cannot be computed."); return(false); } // Check segment if (_SegmentAngle == 0.0) { BRep = faceShape; return(true); } // Do it! var makePrism = ((_SegmentAngle <= -360) || (_SegmentAngle >= 360)) ? new BRepPrimAPI_MakeRevol(faceShape, axis.Value, true) : new BRepPrimAPI_MakeRevol(faceShape, axis.Value, SegmentAngle.Clamp(-360.0, 360.0).ToRad(), true); if (!makePrism.IsDone()) { Messages.Error("The revolving cannot be computed without errors around this axis with the given parameters."); return(false); } // Get final shape BRep = makePrism.Shape(); // Check it var analyzer = new BRepCheck_Analyzer(BRep); if (!analyzer.IsValid()) { Messages.Warning("The resulting solid is not valid and may cause problems in subsequent operations. Check input shape, parameters and axis."); } return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- #endregion #region Make protected override bool MakeInternal(MakeFlags flags) { ClearSubshapeLists(); // Currently we work with 2 source shape only if ((Operands.Count != 2) || (_Face == null)) return false; // Get Target var targetShape = GetOperandBRep(0); if (targetShape == null) return false; var faceShape = GetOperandFace(0, _Face); if (faceShape == null) return false; if (!FaceAlgo.GetCenteredPlaneFromFace(faceShape, out var facePlane)) { Messages.Error("Target face is not planar."); return false; } var baseFacesShape = GetOperand2DFaces(1, facePlane); if (baseFacesShape == null) { Messages.Error("Cannot create faces from 2D operand."); return false; } // If extrusion vector has zero length, or the shape is empty, just copy the source shape if (Depth == 0 || !baseFacesShape.Faces().Any()) { return Skip(); } // Do it! if (DraftAngle != 0) { // DraftPrism needs to change the sign of depth and draft angle var sign = _Mode == ImprintMode.Raise ? 1 : -1; // Make with draft var singleBaseFaces = baseFacesShape.Faces(); foreach (var singleBaseFace in singleBaseFaces) { var makePrism = new BRepFeat_MakeDPrism(targetShape, singleBaseFace, faceShape, _DraftAngle.ToRad()*sign, _Mode == ImprintMode.Raise ? 1 : 0, true); if (_Mode == ImprintMode.Cutout) makePrism.PerformThruAll(); else makePrism.Perform(Depth*sign); UpdateModifiedSubshapes(targetShape, makePrism); UpdateModifiedSubshapes(singleBaseFace, makePrism); targetShape = makePrism.Shape(); } BRep = targetShape; } else { // Generate direction var direction = _Mode == ImprintMode.Raise ? facePlane.Axis.Direction : facePlane.Axis.Direction.Reversed(); // Make w/o draft var makePrism = new BRepFeat_MakePrism(targetShape, baseFacesShape, faceShape, direction, _Mode == ImprintMode.Raise ? 1 : 0, true); if (_Mode == ImprintMode.Cutout) makePrism.PerformThruAll(); else makePrism.Perform(Depth); UpdateModifiedSubshapes(targetShape, makePrism); UpdateModifiedSubshapes(baseFacesShape, makePrism); BRep = makePrism.Shape(); } return base.MakeInternal(flags); }
//-------------------------------------------------------------------------------------------------- #endregion #region Make protected override bool MakeInternal(MakeFlags flags) { ClearSubshapeLists(); ContourEdges.Clear(); if (Operands.Count < 1) { Messages.Error("Chamfer needs at least one operand shape."); return(false); } var sourceShape = GetOperandBRep(0); if (sourceShape == null) { return(false); } // If no edges are selected, just copy the source shape if (Edges.Length == 0) { return(Skip()); } // Create algo var makeChamfer = new BRepFilletAPI_MakeChamfer(sourceShape); // Select edges var edges = GetOcEdges().ToArray(); if (!edges.Any()) { Messages.Error("Edges no longer found. You need to reselect edges to chamfer."); return(false); } // Get reference faces var faces = FindReferenceFaces(sourceShape, edges, ReverseOrientation); // Go for each edge foreach (var edge in edges) { // Get reference face TopoDS_Face face; if (!faces.TryGetValue(edge, out face)) { Messages.Warning("One edge has no ancestor face. Chamfer cannot operator on free edges."); continue; } switch (_Mode) { case ChamferModes.Symmetric: makeChamfer.Add(Distance, edge); break; case ChamferModes.TwoDistances: makeChamfer.Add(Distance, SecondDistance, edge, face); break; case ChamferModes.DistanceAngle: makeChamfer.AddDA(Distance, Angle.ToRad(), edge, face); break; } } // Get final shape BRep = makeChamfer.Shape(); UpdateModifiedSubshapes(sourceShape, makeChamfer); UpdateContourEdges(makeChamfer, edges); return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- #endregion #region Make protected override bool MakeInternal(MakeFlags flags) { ClearSubshapeLists(); // Currently we work with 2 source shape only if ((Operands.Count != 2) || (_Face == null)) { return(false); } // Get Target var targetShape = GetOperandBRep(0); if (targetShape == null) { return(false); } var faceShape = GetOperandFace(0, _Face); if (faceShape == null) { return(false); } if (!FaceAlgo.GetCenteredPlaneFromFace(faceShape, out var facePlane)) { Messages.Error("Target face is not planar."); return(false); } var baseFacesShape = GetOperand2DFaces(1, facePlane); if (baseFacesShape == null) { Messages.Error("Cannot create faces from 2D operand."); return(false); } // Check if we have inner wires (holes), the algo will not work with them when using BRepFeat_MakeDPrism bool useDraft = DraftAngle != 0; if (useDraft) { foreach (var face in baseFacesShape.Faces()) { if (face.Wires().Count > 1) { Messages.Warning("Imprinting a face with holes and draft angle isn't supported. Remove holes and imprint them in a second imprint."); useDraft = false; break; } } } // If extrusion vector has zero length, or the shape is empty, just copy the source shape if (Depth == 0 || !baseFacesShape.Faces().Any()) { return(Skip()); } // Do it! if (useDraft) { // DraftPrism needs to change the sign of depth and draft angle var sign = _Mode == ImprintMode.Raise ? 1 : -1; // Make with draft var singleBaseFaces = baseFacesShape.Faces(); foreach (var singleBaseFace in singleBaseFaces) { var makePrism = new BRepFeat_MakeDPrism(targetShape, singleBaseFace, faceShape, _DraftAngle.ToRad() * sign, _Mode == ImprintMode.Raise ? 1 : 0, true); if (_Mode == ImprintMode.Cutout) { makePrism.PerformThruAll(); } else { makePrism.Perform(Depth * sign); } UpdateModifiedSubshapes(targetShape, makePrism); UpdateModifiedSubshapes(singleBaseFace, makePrism); targetShape = makePrism.Shape(); } BRep = targetShape; } else { // Generate direction var direction = _Mode == ImprintMode.Raise ? facePlane.Axis.Direction : facePlane.Axis.Direction.Reversed(); // Make w/o draft var makePrism = new BRepFeat_MakePrism(targetShape, baseFacesShape, faceShape, direction, _Mode == ImprintMode.Raise ? 1 : 0, true); if (_Mode == ImprintMode.Cutout) { makePrism.PerformThruAll(); } else { makePrism.Perform(Depth); } UpdateModifiedSubshapes(targetShape, makePrism); UpdateModifiedSubshapes(baseFacesShape, makePrism); BRep = makePrism.Shape(); } return(base.MakeInternal(flags)); }
//-------------------------------------------------------------------------------------------------- #region Make protected override bool MakeInternal(MakeFlags flags) { BRep = null; ClearSubshapeLists(); if (Operands.Count < 2) { Messages.Error("Boolean operations need at least two operand shapes."); return(false); } var shapeA = GetOperandBRep(0); if (shapeA == null) { return(false); } var shapeListArgs = new TopTools_ListOfShape(); shapeListArgs.Append(shapeA); var shapeListTools = new TopTools_ListOfShape(); for (int operandIndex = 1; operandIndex < Operands.Count; operandIndex++) { var shapeB = GetOperandBRep(operandIndex); if (shapeB == null) { return(false); } shapeListTools.Append(shapeB); } var algo = CreateAlgoApi(); algo.SetArguments(shapeListArgs); algo.SetTools(shapeListTools); algo.Build(); if (!algo.IsDone()) { Messages.Error("Boolean operation failed."); return(false); } var resultShape = algo.Shape(); if (resultShape == null) { return(false); } UpdateModifiedSubshapes(shapeA, algo); foreach (var shapeB in shapeListTools.ToList()) { UpdateModifiedSubshapes(shapeB, algo); } BRep = resultShape; return(base.MakeInternal(flags)); }