]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Flyout implemented for parallel and perpendicular constraints
authorazv <azv@opencascade.com>
Thu, 26 Jun 2014 14:10:13 +0000 (18:10 +0400)
committerazv <azv@opencascade.com>
Thu, 26 Jun 2014 14:10:13 +0000 (18:10 +0400)
src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp
src/SketchPlugin/SketchPlugin_ConstraintParallel.h
src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp
src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h
src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp

index 92e23ead40c5c274df3cc10ab2bf83b5b4dc5bc5..f77c95d27ad041f871daaaabb84a9542b5e882e5 100644 (file)
@@ -6,13 +6,17 @@
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
+
 #include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
 
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_ParallelRelation.hxx>
 #include <Geom_Plane.hxx>
 
 #include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Pnt.h>
 
 SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel()
 {
@@ -61,11 +65,16 @@ Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle
   boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
   Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
 
+  boost::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+  boost::shared_ptr<GeomAPI_Pnt2d> aFOPnt2d = aFlyoutAttr->pnt();
+  boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFOPnt2d->x(), aFOPnt2d->y());
+
   if (anAIS.IsNull())
   {
     Handle(AIS_ParallelRelation) aParallel = 
       new AIS_ParallelRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
-
+    aParallel->SetPosition(aFlyoutPnt->impl<gp_Pnt>());
     anAIS = aParallel;
   }
   else
@@ -76,9 +85,21 @@ Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle
       aParallel->SetFirstShape(aLine1->impl<TopoDS_Shape>());
       aParallel->SetSecondShape(aLine2->impl<TopoDS_Shape>());
       aParallel->SetPlane(aPlane);
+      aParallel->SetPosition(aFlyoutPnt->impl<gp_Pnt>());
       aParallel->Redisplay(Standard_True);
     }
   }
   return anAIS;
 }
 
+void SketchPlugin_ConstraintParallel::move(double theDeltaX, double theDeltaY)
+{
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  if (!aData->isValid())
+    return;
+
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+  aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);
+}
+
index eae4fcfbbcb614512f741adaadfc2f3a035c18b5..9496f0722138a2e2adb5553f2e3667d6e64aed39 100644 (file)
@@ -42,6 +42,11 @@ public:
   /// Returns the AIS preview
   SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
 
+  /// Moves the feature
+  /// \param theDeltaX the delta for X coordinate is moved
+  /// \param theDeltaY the delta for Y coordinate is moved
+  SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintParallel();
 };
index d3646af7e083cade81dba5c5d700872d8b8619a0..1b6cc4d095d270e16afd86d21c85ec0a690d04b0 100644 (file)
@@ -4,16 +4,20 @@
 
 #include "SketchPlugin_ConstraintPerpendicular.h"
 
-#include <GeomDataAPI_Point2D.h>
-
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
+
 #include <SketchPlugin_Line.h>
+#include <SketchPlugin_Sketch.h>
 
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_PerpendicularRelation.hxx>
 #include <Geom_Plane.hxx>
 
+#include <GeomDataAPI_Point2D.h>
+#include <GeomAPI_Pnt2d.h>
+#include <GeomAPI_Pnt.h>
+
 SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
 {
 }
@@ -60,11 +64,16 @@ Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(H
   boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
   Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
 
+  boost::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+  boost::shared_ptr<GeomAPI_Pnt2d> aFOPnt2d = aFlyoutAttr->pnt();
+  boost::shared_ptr<GeomAPI_Pnt> aFlyoutPnt = sketch()->to3D(aFOPnt2d->x(), aFOPnt2d->y());
+
   if (anAIS.IsNull())
   {
     Handle(AIS_PerpendicularRelation) aPerpendicular = 
       new AIS_PerpendicularRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
-
+    aPerpendicular->SetPosition(aFlyoutPnt->impl<gp_Pnt>());
     anAIS = aPerpendicular;
   }
   else
@@ -75,9 +84,21 @@ Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(H
       aPerpendicular->SetFirstShape(aLine1->impl<TopoDS_Shape>());
       aPerpendicular->SetSecondShape(aLine2->impl<TopoDS_Shape>());
       aPerpendicular->SetPlane(aPlane);
+      aPerpendicular->SetPosition(aFlyoutPnt->impl<gp_Pnt>());
       aPerpendicular->Redisplay(Standard_True);
     }
   }
   return anAIS;
 }
 
+void SketchPlugin_ConstraintPerpendicular::move(double theDeltaX, double theDeltaY)
+{
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  if (!aData->isValid())
+    return;
+
+  boost::shared_ptr<GeomDataAPI_Point2D> aPoint =
+        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+  aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY);
+}
+
index 68b733e8c2aa89c9243a5d321938b1d318b65fbf..c960f50e869f3b94dc724de2e3825fd621290598 100644 (file)
@@ -42,6 +42,11 @@ public:
   /// Returns the AIS preview
   SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
 
+  /// Moves the feature
+  /// \param theDeltaX the delta for X coordinate is moved
+  /// \param theDeltaY the delta for Y coordinate is moved
+  SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY);
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintPerpendicular();
 };
index 6f4d17670498c8bd11569408487bd4d75480541e..391dbd451e43d63421abdf8d4abd1e3bee1eb2c6 100644 (file)
@@ -13,6 +13,9 @@
 
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Circ.h>
+#include <GeomAPI_Circ2d.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_XYZ.h>
 #include <GeomDataAPI_Point2D.h>
 #include <GeomDataAPI_Dir.h>
 
@@ -123,14 +126,13 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape(
   // We want to show a radius dimension starting from the circle centre and 
   // ending at the user-defined point.
   // Also, if anchor point coincides with myP2, the radius dimension is not displayed at all.
-  gp_Pnt anAPnt = anAnchor->impl<gp_Pnt>();
-  double aDelta = 1/1000.0;
-  if (anAnchor->x() != 0)
-    anAnchor->setX(anAnchor->x() + aDelta);
-  if (anAnchor->y() != 0)
-    anAnchor->setY(anAnchor->y() + aDelta);
-  if (anAnchor->z() != 0)
-    anAnchor->setZ(anAnchor->z() + aDelta);
+  boost::shared_ptr<GeomAPI_XYZ> anAnchorXYZ = anAnchor->xyz();
+  anAnchorXYZ = anAnchorXYZ->decreased(aCenter->xyz());
+  boost::shared_ptr<GeomAPI_Dir> aDeltaDir(new GeomAPI_Dir(anAnchorXYZ));
+  const double aDelta = 1e-3;
+  anAnchor->setX(anAnchor->x() + aDelta * aDeltaDir->x());
+  anAnchor->setY(anAnchor->y() + aDelta * aDeltaDir->y());
+  anAnchor->setZ(anAnchor->z() + aDelta * aDeltaDir->z());
 
   if (anAIS.IsNull())
   {
@@ -169,7 +171,34 @@ void SketchPlugin_ConstraintRadius::move(double theDeltaX, double theDeltaY)
   if (!aData->isValid())
     return;
 
-  boost::shared_ptr<GeomDataAPI_Point2D> aPoint1 =
-        boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
-  aPoint1->setValue(aPoint1->x() + theDeltaX, aPoint1->y() + theDeltaY);
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
+    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(data()->attribute(CONSTRAINT_ATTR_ENTITY_A));
+  FeaturePtr aFeature = aRef->feature();
+  if (!aFeature)
+    return;
+  std::string aCenterAttrName;
+  if (aFeature->getKind() == SKETCH_CIRCLE_KIND)
+    aCenterAttrName = CIRCLE_ATTR_CENTER;
+  else if (aFeature->getKind() == SKETCH_ARC_KIND)
+    aCenterAttrName = ARC_ATTR_CENTER;
+  boost::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = 
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aFeature->data()->attribute(aCenterAttrName));
+  boost::shared_ptr<GeomAPI_Pnt2d> aCenter = aCenterAttr->pnt();
+
+  // The specified delta applied on the circle curve, 
+  // so it will be scaled due to distance between flyout and center points
+  boost::shared_ptr<GeomDataAPI_Point2D> aFlyoutAttr =
+    boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT));
+  boost::shared_ptr<GeomAPI_Pnt2d> aFlyout = aFlyoutAttr->pnt();
+
+  boost::shared_ptr<ModelAPI_AttributeDouble> aRadius =
+    boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(aData->attribute(CONSTRAINT_ATTR_VALUE));
+  double aScale = aFlyout->distance(aCenter) / aRadius->value();
+
+  boost::shared_ptr<GeomAPI_Circ2d> aCircle(new GeomAPI_Circ2d(aCenter, aFlyout));
+  aFlyout->setX(aFlyout->x() + aScale * theDeltaX);
+  aFlyout->setY(aFlyout->y() + aScale * theDeltaY);
+  aFlyout = aCircle->project(aFlyout);
+
+  aFlyoutAttr->setValue(aFlyout->x(), aFlyout->y());
 }