Salome HOME
Remove DirY from Sketch attributes
[modules/shaper.git] / src / PartSet / PartSet_Tools.cpp
index 0b07da7e75db47c670207a7138059a3b9048c0fe..f7c4ab57f0c6fde0261324b1410766d0acf8a20b 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,
@@ -361,6 +363,8 @@ void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr the
       new GeomAPI_Pnt2d(theClickedX, theClickedY));
   for (; anIt != aLast; anIt++) {
     FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
+    if (theFeature == aFeature)
+      continue;
     // find the given point in the feature attributes
     anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::type());
     std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt = anAttiributes.begin(),
@@ -415,25 +419,19 @@ 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()));
-
-  return thePoint2D->to3D(aC->pnt(), aX->dir(), aY->dir());
-}
+      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())));
 
-bool PartSet_Tools::isConstraintFeature(const std::string& theKind)
-{
-  return theKind == SketchPlugin_ConstraintDistance::ID()
-      || theKind == SketchPlugin_ConstraintLength::ID()
-      || theKind == SketchPlugin_ConstraintRadius::ID()
-      || theKind == SketchPlugin_ConstraintRigid::ID();
+  return thePoint2D->to3D(aC->pnt(), aX->dir(), aY);
 }
 
-ResultPtr PartSet_Tools::createFixedObjectByEdge(const TopoDS_Shape& theShape, 
+ResultPtr PartSet_Tools::createFixedObjectByExternal(const TopoDS_Shape& theShape, 
                                                  const ObjectPtr& theObject, 
                                                  CompositeFeaturePtr theSketch)
 {
@@ -468,7 +466,7 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const TopoDS_Shape& theShape,
       DataPtr aData = aMyFeature->data();
       AttributeSelectionPtr anAttr = 
         std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-        (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+        (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
 
       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
       if (anAttr && aRes) {
@@ -501,7 +499,7 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const TopoDS_Shape& theShape,
       DataPtr aData = aMyFeature->data();
       AttributeSelectionPtr anAttr = 
         std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-        (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+        (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
 
       ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
       if (anAttr && aRes) {