]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/SketchAPI/SketchAPI_Sketch.cpp
Salome HOME
fix coding style
[modules/shaper.git] / src / SketchAPI / SketchAPI_Sketch.cpp
index 2f6ffcdfab9befdf7692b55cb511d53a661b5fd5..de5799715a6ce748122dc6fca2215cee474b4be0 100644 (file)
@@ -223,7 +223,7 @@ SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
 }
 
 SketchPtr addSketch(const std::shared_ptr<ModelAPI_Document> & thePart,
-                    const std::string & theExternalName)
+                    const std::wstring & theExternalName)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature = thePart->addFeature(SketchAPI_Sketch::ID());
   return SketchPtr(
@@ -349,7 +349,7 @@ std::shared_ptr<SketchAPI_Point>
     compositeFeature()->addFeature(SketchPlugin_Point::ID());
   return PointPtr(new SketchAPI_Point(aFeature, theExternal));
 }
-std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::string & theExternalName)
+std::shared_ptr<SketchAPI_Point> SketchAPI_Sketch::addPoint(const std::wstring & theExternalName)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
     compositeFeature()->addFeature(SketchPlugin_Point::ID());
@@ -368,7 +368,7 @@ std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPo
   return anIntersection;
 }
 std::shared_ptr<SketchAPI_IntersectionPoint> SketchAPI_Sketch::addIntersectionPoint(
-    const std::string & theExternalName,
+    const std::wstring & theExternalName,
     bool theKeepResult)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
@@ -401,7 +401,7 @@ std::shared_ptr<SketchAPI_Line>
     compositeFeature()->addFeature(SketchPlugin_Line::ID());
   return LinePtr(new SketchAPI_Line(aFeature, theExternal));
 }
-std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::string & theExternalName)
+std::shared_ptr<SketchAPI_Line> SketchAPI_Sketch::addLine(const std::wstring & theExternalName)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
     compositeFeature()->addFeature(SketchPlugin_Line::ID());
@@ -425,6 +425,40 @@ std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
   return RectanglePtr(new SketchAPI_Rectangle(aFeature, theStartPoint, theEndPoint));
 }
 
+std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
+    double theX1, double theY1, double theX2, double theY2, bool isFirstPointCenter)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
+  return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1,
+                                              theX2, theY2, isFirstPointCenter));
+}
+std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangle(
+    const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
+    const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint,  bool isFirstPointCenter)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
+  return RectanglePtr(new SketchAPI_Rectangle(aFeature, theFirstPoint, theEndPoint,
+                                              isFirstPointCenter));
+}
+
+std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangleCentered(
+    double theX1, double theY1, double theX2, double theY2)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
+  return RectanglePtr(new SketchAPI_Rectangle(aFeature, theX1, theY1, theX2, theY2, true));
+}
+std::shared_ptr<SketchAPI_Rectangle> SketchAPI_Sketch::addRectangleCentered(
+    const std::shared_ptr<GeomAPI_Pnt2d> & theFirstPoint,
+    const std::shared_ptr<GeomAPI_Pnt2d> & theEndPoint)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+    compositeFeature()->addFeature(SketchAPI_Rectangle::ID());
+  return RectanglePtr(new SketchAPI_Rectangle(aFeature, theFirstPoint, theEndPoint, true));
+}
+
 //--------------------------------------------------------------------------------------
 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(double theCenterX,
                                                               double theCenterY,
@@ -493,7 +527,7 @@ std::shared_ptr<SketchAPI_Circle>
   return CirclePtr(new SketchAPI_Circle(aFeature, theExternal));
 }
 
-std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
+std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::wstring & theExternalName)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
     compositeFeature()->addFeature(SketchPlugin_Circle::ID());
@@ -587,7 +621,7 @@ std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selec
   return ArcPtr(new SketchAPI_Arc(aFeature, theExternal));
 }
 
-std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
+std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::wstring & theExternalName)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
     compositeFeature()->addFeature(SketchPlugin_Arc::ID());
@@ -662,7 +696,7 @@ std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
 }
 
 std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
-    const std::string & theExternalName)
+    const std::wstring & theExternalName)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
       compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
@@ -713,7 +747,7 @@ std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
 }
 
 std::shared_ptr<SketchAPI_EllipticArc> SketchAPI_Sketch::addEllipticArc(
-    const std::string & theExternalName)
+    const std::wstring & theExternalName)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
       compositeFeature()->addFeature(SketchPlugin_EllipticArc::ID());
@@ -861,23 +895,15 @@ std::shared_ptr<SketchAPI_BSpline> SketchAPI_Sketch::addApproximation(
 //--------------------------------------------------------------------------------------
 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
     const ModelHighAPI_Selection & theExternalFeature,
-    bool theKeepResult)
+    bool keepResult,
+    bool keepRefToOriginal)
 {
   std::shared_ptr<ModelAPI_Feature> aFeature =
     compositeFeature()->addFeature(SketchPlugin_Projection::ID());
-  ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalFeature));
-  aProjection->setIncludeToResult(theKeepResult);
-  return aProjection;
-}
-
-std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
-    const std::string & theExternalName,
-    bool theKeepResult)
-{
-  std::shared_ptr<ModelAPI_Feature> aFeature =
-    compositeFeature()->addFeature(SketchPlugin_Projection::ID());
-  ProjectionPtr aProjection(new SketchAPI_Projection(aFeature, theExternalName));
-  aProjection->setIncludeToResult(theKeepResult);
+  ProjectionPtr aProjection(new SketchAPI_Projection(aFeature));
+  aProjection->setIncludeToResult(keepResult);
+  aProjection->setKeepReferenceToOriginal(keepRefToOriginal);
+  aProjection->setExternalFeature(theExternalFeature);
   return aProjection;
 }
 
@@ -1549,7 +1575,7 @@ void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
         aBase->attribute(SketchPlugin_Sketch::DIRX_ID()))->dir();
 
     // Check the plane is coordinate plane
-    std::string aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
+    std::wstring aPlaneName = defaultPlane(anOrigin, aNormal, aDirX);
     if(anExternal->context()) { // checking for selected planes
       if (!aPlaneName.empty()
           && anExternal->context()->data()
@@ -1596,6 +1622,34 @@ void SketchAPI_Sketch::dump(ModelHighAPI_Dumper& theDumper) const
     std::list<std::list<ResultPtr> > aFaces;
     edgesOfSketchFaces(aCompFeat, aFaces);
 
+    /// remove faces that must not be dumped
+    std::vector< std::list<std::list<ResultPtr>>::iterator> aFacesToRemove;
+    for(auto itFaces = aFaces.begin(); itFaces != aFaces.end(); ++itFaces)
+    {
+      auto & facesGroup = *itFaces;
+      std::vector<std::list<ResultPtr>::iterator> subFacestoRemove;
+      for(auto itGroup = facesGroup.begin(); itGroup != facesGroup.end(); ++itGroup)
+      {
+        FeaturePtr aFeature = ModelAPI_Feature::feature(*itGroup);
+        if(theDumper.isDumped(aFeature)){
+          subFacestoRemove.push_back(itGroup);
+        }
+      }
+      for(auto itGroup :subFacestoRemove){
+        facesGroup.erase(itGroup);
+      }
+
+      if(!facesGroup.size()){
+        aFacesToRemove.push_back(itFaces);
+      }
+    }
+    for(auto itFaces :aFacesToRemove){
+      aFaces.erase(itFaces);
+    }
+
+    if(!aFaces.size())
+      return;
+
     const std::string& aSketchName = theDumper.name(aBase);
     std::string aMethodName(".changeFacesOrder");
     std::string aSpaceShift(aSketchName.size() + aMethodName.size(), ' ');