]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Sketcher Offset: closed offset for closed wire.
authorjfa <jfa@opencascade.com>
Fri, 26 Jun 2020 13:01:37 +0000 (16:01 +0300)
committerjfa <jfa@opencascade.com>
Fri, 26 Jun 2020 13:01:37 +0000 (16:01 +0300)
src/GeomAPI/GeomAPI_BSpline.cpp
src/GeomAPI/GeomAPI_BSpline.h
src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp
src/SketchPlugin/SketchPlugin_Offset.cpp

index 6b4c0fe84e83fc96d812f7f3025633f4fbfedf4b..b785aa77b0e269e31964be9838d4c2493d7b84c3 100644 (file)
 
 #define MY_BSPLINE (*(implPtr<Handle_Geom_BSplineCurve>()))
 
-GeomAPI_BSpline::GeomAPI_BSpline (const GeomCurvePtr& theCurve,
-                                  const bool isForced)
+GeomAPI_BSpline::GeomAPI_BSpline (const GeomCurvePtr& theCurve)
 {
   GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve();
   Handle(Geom_Curve) aCurve = anUntrimmedCurve->impl<Handle(Geom_Curve)>();
   Handle(Geom_BSplineCurve) aBSpl = Handle(Geom_BSplineCurve)::DownCast(aCurve);
-  if (aBSpl.IsNull() && isForced) {
-    // convert to b-spline
-    aBSpl = GeomConvert::CurveToBSplineCurve(aCurve);
-  }
   if (aBSpl.IsNull())
     throw Standard_ConstructionError("GeomAPI_BSpline: Curve is not a B-spline");
   setImpl(new Handle_Geom_BSplineCurve(aBSpl));
@@ -83,3 +78,20 @@ bool GeomAPI_BSpline::isPeriodic() const
 {
   return MY_BSPLINE->IsPeriodic();
 }
+
+GeomBSplinePtr GeomAPI_BSpline::convertToBSpline (const GeomCurvePtr& theCurve)
+{
+  GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve();
+  Handle(Geom_Curve) aCurve = anUntrimmedCurve->impl<Handle(Geom_Curve)>();
+  Handle(Geom_BSplineCurve) aBSpl = Handle(Geom_BSplineCurve)::DownCast(aCurve);
+  if (aBSpl.IsNull()) {
+    // convert to b-spline
+    aBSpl = GeomConvert::CurveToBSplineCurve(aCurve);
+  }
+  if (aBSpl.IsNull())
+    throw Standard_ConstructionError("GeomAPI_BSpline: Conversion to B-spline failed");
+  GeomCurvePtr aResCurve (new GeomAPI_Curve());
+  aResCurve->setImpl(new Handle_Geom_BSplineCurve(aBSpl));
+  GeomBSplinePtr aResult (new GeomAPI_BSpline(aResCurve));
+  return aResult;
+}
index 275b94dda46ff98b968ffad96b5cc70382120f39..251122dd8c93f270eef921dcc7cef466fd2981fc 100644 (file)
 #include <memory>
 
 class GeomAPI_Pnt;
+class GeomAPI_BSpline;
+
+//! Pointer on the object
+typedef std::shared_ptr<GeomAPI_BSpline> GeomBSplinePtr;
 
 /**\class GeomAPI_BSpline
  * \ingroup DataModel
@@ -36,10 +40,7 @@ class GeomAPI_BSpline : public GeomAPI_Interface
 {
 public:
   /// Creation of B-spline defined by a curve
-  /// \param isForced if true and theCurve is not a b-spline
-  ///                 curve, theCurve is converted to b-spline
-  GEOMAPI_EXPORT GeomAPI_BSpline (const GeomCurvePtr& theCurve,
-                                  const bool isForced = false);
+  GEOMAPI_EXPORT GeomAPI_BSpline (const GeomCurvePtr& theCurve);
 
   /// Degree of B-spline curve
   GEOMAPI_EXPORT int degree() const;
@@ -58,9 +59,9 @@ public:
 
   /// Return \c true if the curve is periodic
   GEOMAPI_EXPORT bool isPeriodic() const;
-};
 
-//! Pointer on the object
-typedef std::shared_ptr<GeomAPI_BSpline> GeomBSplinePtr;
+  /// Convert any curve into a B-spline curve
+  GEOMAPI_EXPORT static GeomBSplinePtr convertToBSpline (const GeomCurvePtr& theCurve);
+};
 
 #endif
index 4b0bb4031f51d42b85e808be836b9e478a3e5956..437a2a97c51b7eacafde626417e001546ab67c33 100644 (file)
@@ -92,7 +92,8 @@ GeomAlgoAPI_Offset::GeomAlgoAPI_Offset(const GeomPlanePtr& thePlane,
   setImpl(aParal);
   setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
 
-  aParal->Init(aFace, GeomAbs_Arc, Standard_True);
+  Standard_Boolean isOpenResult = !aWire.Closed();
+  aParal->Init(aFace, GeomAbs_Arc, isOpenResult);
   aParal->Perform(theOffsetValue, 0.);
   if (aParal->IsDone()) {
     TopoDS_Shape anOffset = aParal->Shape();
index cc523494342d81da9ca6bbf1c705e7b95a64eaaf..97798f7a15ea6e0d3a2e2490d3a4492a680dc7e5 100644 (file)
@@ -579,17 +579,17 @@ void SketchPlugin_Offset::mkBSpline (FeaturePtr& theResult,
 {
   GeomCurvePtr aCurve (new GeomAPI_Curve (theEdge));
   // Forced conversion to b-spline, if aCurve is not b-spline
-  GeomAPI_BSpline aBSpline (aCurve, /*isForced*/true);
+  GeomBSplinePtr aBSpline = GeomAPI_BSpline::convertToBSpline(aCurve);
 
-  const std::string& aBSplineKind = aBSpline.isPeriodic() ? SketchPlugin_BSplinePeriodic::ID()
-                                                          : SketchPlugin_BSpline::ID();
+  const std::string& aBSplineKind = aBSpline->isPeriodic() ? SketchPlugin_BSplinePeriodic::ID()
+                                                           : SketchPlugin_BSpline::ID();
   findOrCreateFeatureByKind(sketch(), aBSplineKind, theResult, thePoolOfFeatures);
 
-  theResult->integer(SketchPlugin_BSpline::DEGREE_ID())->setValue(aBSpline.degree());
+  theResult->integer(SketchPlugin_BSpline::DEGREE_ID())->setValue(aBSpline->degree());
 
   AttributePoint2DArrayPtr aPolesAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>
     (theResult->attribute(SketchPlugin_BSpline::POLES_ID()));
-  std::list<GeomPointPtr> aPoles = aBSpline.poles();
+  std::list<GeomPointPtr> aPoles = aBSpline->poles();
   aPolesAttr->setSize((int)aPoles.size());
   std::list<GeomPointPtr>::iterator anIt = aPoles.begin();
   for (int anIndex = 0; anIt != aPoles.end(); ++anIt, ++anIndex) {
@@ -599,7 +599,7 @@ void SketchPlugin_Offset::mkBSpline (FeaturePtr& theResult,
 
   AttributeDoubleArrayPtr aWeightsAttr =
       theResult->data()->realArray(SketchPlugin_BSpline::WEIGHTS_ID());
-  std::list<double> aWeights = aBSpline.weights();
+  std::list<double> aWeights = aBSpline->weights();
   if (aWeights.empty()) { // rational B-spline
     int aSize = (int)aPoles.size();
     aWeightsAttr->setSize(aSize);
@@ -615,7 +615,7 @@ void SketchPlugin_Offset::mkBSpline (FeaturePtr& theResult,
 
   AttributeDoubleArrayPtr aKnotsAttr =
       theResult->data()->realArray(SketchPlugin_BSpline::KNOTS_ID());
-  std::list<double> aKnots = aBSpline.knots();
+  std::list<double> aKnots = aBSpline->knots();
   int aSize = (int)aKnots.size();
   aKnotsAttr->setSize(aSize);
   std::list<double>::iterator aKIt = aKnots.begin();
@@ -624,7 +624,7 @@ void SketchPlugin_Offset::mkBSpline (FeaturePtr& theResult,
 
   AttributeIntArrayPtr aMultsAttr =
       theResult->data()->intArray(SketchPlugin_BSpline::MULTS_ID());
-  std::list<int> aMultiplicities = aBSpline.mults();
+  std::list<int> aMultiplicities = aBSpline->mults();
   aSize = (int)aMultiplicities.size();
   aMultsAttr->setSize(aSize);
   std::list<int>::iterator aMIt = aMultiplicities.begin();