Salome HOME
The external edge should be removed only if it was created by the widget. So, the...
[modules/shaper.git] / src / PartSet / PartSet_Tools.cpp
index 56f1ac3fc83708bdb32db18c07286b58c225aa4b..82675355b292f78aeec6255f5ac6ad880d81757a 100644 (file)
@@ -99,8 +99,9 @@ Handle(V3d_View) theView,
 
   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> anY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+  std::shared_ptr<GeomAPI_XYZ> anY = aNorm->xyz()->cross(aX->xyz());
 
   gp_Pnt anOriginPnt(anOrigin->x(), anOrigin->y(), anOrigin->z());
   gp_Vec aVec(anOriginPnt, thePoint);
@@ -138,13 +139,14 @@ std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::convertTo3D(const double theX, const
       aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
       aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      aData->attribute(SketchPlugin_Sketch::DIRY_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+  std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
 
   std::shared_ptr<GeomAPI_Pnt2d> aPnt2d = 
     std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(theX, theY));
 
-  return aPnt2d->to3D(aC->pnt(), aX->dir(), aY->dir());
+  return aPnt2d->to3D(aC->pnt(), aX->dir(), aY);
 }
 
 ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
@@ -220,7 +222,7 @@ std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::getFeaturePoint(FeaturePtr t
   std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
                                                                  new GeomAPI_Pnt2d(theX, theY));
   std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes =
-                                    theFeature->data()->attributes(GeomDataAPI_Point2D::type());
+                                    theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
   std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
                                                                     aLast = anAttiributes.end();
   std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
@@ -319,7 +321,7 @@ std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
   for (int i = 0; i < theSketch->numberOfSubs(); i++) {
     FeaturePtr aFeature = theSketch->subFeature(i);
     if (!theIgnore.contains(aFeature)) {
-      anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::type());
+      anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
 
       std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt;
       for (anIt = anAttiributes.cbegin(); anIt != anAttiributes.cend(); ++anIt) {
@@ -364,7 +366,7 @@ void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr the
     if (theFeature == aFeature)
       continue;
     // find the given point in the feature attributes
-    anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::type());
+    anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
     std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
         aLast = anAttiributes.end();
     std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
@@ -417,29 +419,42 @@ std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(std::shared_ptr<GeomAPI_Pnt2
   if (!theSketch || !thePoint2D)
     return aPoint;
 
+  DataPtr aData = theSketch->data();
   std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
-      theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+      aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
   std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      theSketch->data()->attribute(SketchPlugin_Sketch::DIRX_ID()));
-  std::shared_ptr<GeomDataAPI_Dir> aY = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
-      theSketch->data()->attribute(SketchPlugin_Sketch::DIRY_ID()));
+      aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
+  std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+      aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+  std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
 
-  return thePoint2D->to3D(aC->pnt(), aX->dir(), aY->dir());
+  return thePoint2D->to3D(aC->pnt(), aX->dir(), aY);
 }
 
-ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, 
-                                                 const ObjectPtr& theObject, 
-                                                 CompositeFeaturePtr theSketch)
+ResultPtr PartSet_Tools::findFixedObjectByExternal(const TopoDS_Shape& theShape,
+                                                   const ObjectPtr& theObject,
+                                                   CompositeFeaturePtr theSketch)
 {
+  ResultPtr aResult;
   if (theShape.ShapeType() == TopAbs_EDGE) {
     // Check that we already have such external edge
     std::shared_ptr<GeomAPI_Edge> aInEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
     aInEdge->setImpl(new TopoDS_Shape(theShape));
-    ResultPtr aResult = findExternalEdge(theSketch, aInEdge);
-    if (aResult)
-      return aResult;
+    aResult = findExternalEdge(theSketch, aInEdge);
+  }
+  if (theShape.ShapeType() == TopAbs_VERTEX) {
+    std::shared_ptr<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex());
+    aInVert->setImpl(new TopoDS_Shape(theShape));
+    aResult = findExternalVertex(theSketch, aInVert);
+  }
+  return aResult;
+}
 
-    // If not found then we have to create new
+ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, 
+                                                 const ObjectPtr& theObject, 
+                                                 CompositeFeaturePtr theSketch)
+{
+  if (theShape.ShapeType() == TopAbs_EDGE) {
     Standard_Real aStart, aEnd;
     Handle(V3d_View) aNullView;
     FeaturePtr aMyFeature;
@@ -483,12 +498,6 @@ ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShap
     }
   }
   if (theShape.ShapeType() == TopAbs_VERTEX) {
-    std::shared_ptr<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex());
-    aInVert->setImpl(new TopoDS_Shape(theShape));
-    ResultPtr aResult = findExternalVertex(theSketch, aInVert);
-    if (aResult)
-      return aResult;
-
     FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID());
 
     if (aMyFeature) {
@@ -620,7 +629,7 @@ AttributePtr PartSet_Tools::findAttributeBy2dPoint(ObjectPtr theObj,
 
         // find the given point in the feature attributes
         std::list<AttributePtr> anAttiributes = 
-          aFeature->data()->attributes(GeomDataAPI_Point2D::type());
+          aFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
         std::list<AttributePtr>::const_iterator anIt = anAttiributes.begin(), 
                                                 aLast = anAttiributes.end();
         for (; anIt != aLast && !anAttribute; anIt++) {