]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Presentation for parallel and perpendicular constraints
authorazv <azv@opencascade.com>
Thu, 26 Jun 2014 04:44:45 +0000 (08:44 +0400)
committerazv <azv@opencascade.com>
Thu, 26 Jun 2014 04:44:45 +0000 (08:44 +0400)
src/SketchPlugin/SketchPlugin_ConstraintParallel.cpp
src/SketchPlugin/SketchPlugin_ConstraintParallel.h
src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp
src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.h
src/SketchSolver/SketchSolver_ConstraintGroup.cpp

index 91e6c4ca52fa1e6500a538809e759e6fc01caf49..342b2c1de18a81f2fb42e825669971b2509083f3 100644 (file)
@@ -6,7 +6,11 @@
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
-#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Line.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_ParallelRelation.hxx>
+#include <Geom_Plane.hxx>
 
 SketchPlugin_ConstraintParallel::SketchPlugin_ConstraintParallel()
 {
@@ -28,3 +32,50 @@ const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintParallel::previe
   return getPreview();
 }
 
+
+Handle_AIS_InteractiveObject SketchPlugin_ConstraintParallel::getAISShape(Handle_AIS_InteractiveObject thePrevious)
+{
+  Handle(AIS_InteractiveObject) anAIS = thePrevious;
+  if (!sketch())
+    return anAIS;
+
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
+  if (!anAttr1 || !anAttr1->isFeature() || 
+      !anAttr2 || !anAttr2->isFeature())
+    return anAIS;
+  boost::shared_ptr<SketchPlugin_Line> aLine1Feature = 
+    boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
+  boost::shared_ptr<SketchPlugin_Line> aLine2Feature = 
+    boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
+  if (!aLine1Feature || !aLine2Feature)
+    return anAIS;
+
+  boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
+  boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
+  Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
+
+  if (anAIS.IsNull())
+  {
+    Handle(AIS_ParallelRelation) aParallel = 
+      new AIS_ParallelRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
+
+    anAIS = aParallel;
+  }
+  else
+  {
+    Handle(AIS_ParallelRelation) aParallel = Handle(AIS_ParallelRelation)::DownCast(anAIS);
+    if (!aParallel.IsNull())
+    {
+      aParallel->SetFirstShape(aLine1->impl<TopoDS_Shape>());
+      aParallel->SetSecondShape(aLine2->impl<TopoDS_Shape>());
+      aParallel->SetPlane(aPlane);
+      aParallel->Redisplay(Standard_True);
+    }
+  }
+  return anAIS;
+}
+
index ac209b68fd75988661bfdccae9418d0e18234a30..eae4fcfbbcb614512f741adaadfc2f3a035c18b5 100644 (file)
@@ -39,6 +39,9 @@ public:
   /// \brief Returns the sketch preview
   SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
 
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintParallel();
 };
index 85c543f2b968d79d3d7db8202a946fd200df29fb..ca5e229728e7a777f12c9e00da517b739af8ba2c 100644 (file)
@@ -6,7 +6,11 @@
 
 #include <ModelAPI_AttributeDouble.h>
 #include <ModelAPI_Data.h>
-#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Line.h>
+
+#include <AIS_InteractiveObject.hxx>
+#include <AIS_PerpendicularRelation.hxx>
+#include <Geom_Plane.hxx>
 
 SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular()
 {
@@ -28,3 +32,49 @@ const boost::shared_ptr<GeomAPI_Shape>&  SketchPlugin_ConstraintPerpendicular::p
   return getPreview();
 }
 
+Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(Handle_AIS_InteractiveObject thePrevious)
+{
+  Handle(AIS_InteractiveObject) anAIS = thePrevious;
+  if (!sketch())
+    return anAIS;
+
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr1 = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_A));
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr2 = 
+    boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aData->attribute(CONSTRAINT_ATTR_ENTITY_B));
+  if (!anAttr1 || !anAttr1->isFeature() || 
+      !anAttr2 || !anAttr2->isFeature())
+    return anAIS;
+  boost::shared_ptr<SketchPlugin_Line> aLine1Feature = 
+    boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr1->feature());
+  boost::shared_ptr<SketchPlugin_Line> aLine2Feature = 
+    boost::dynamic_pointer_cast<SketchPlugin_Line>(anAttr2->feature());
+  if (!aLine1Feature || !aLine2Feature)
+    return anAIS;
+
+  boost::shared_ptr<GeomAPI_Shape> aLine1 = aLine1Feature->preview();
+  boost::shared_ptr<GeomAPI_Shape> aLine2 = aLine2Feature->preview();
+  Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl<gp_Pln>());
+
+  if (anAIS.IsNull())
+  {
+    Handle(AIS_PerpendicularRelation) aPerpendicular = 
+      new AIS_PerpendicularRelation(aLine1->impl<TopoDS_Shape>(), aLine2->impl<TopoDS_Shape>(), aPlane);
+
+    anAIS = aPerpendicular;
+  }
+  else
+  {
+    Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
+    if (!aPerpendicular.IsNull())
+    {
+      aPerpendicular->SetFirstShape(aLine1->impl<TopoDS_Shape>());
+      aPerpendicular->SetSecondShape(aLine2->impl<TopoDS_Shape>());
+      aPerpendicular->SetPlane(aPlane);
+      aPerpendicular->Redisplay(Standard_True);
+    }
+  }
+  return anAIS;
+}
+
index 475c330849c3c35095878230876cc22493e2cd16..68b733e8c2aa89c9243a5d321938b1d318b65fbf 100644 (file)
@@ -39,6 +39,9 @@ public:
   /// \brief Returns the sketch preview
   SKETCHPLUGIN_EXPORT virtual const boost::shared_ptr<GeomAPI_Shape>& preview();
 
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual Handle_AIS_InteractiveObject getAISShape(Handle_AIS_InteractiveObject thePrevious);
+
   /// \brief Use plugin manager for features creation
   SketchPlugin_ConstraintPerpendicular();
 };
index 0676bd58c6faf2a0b30803007f2cc0da08121245..d54915677b9f3ceffc9560e94fd574e6e9440145 100644 (file)
@@ -209,11 +209,17 @@ bool SketchSolver_ConstraintGroup::changeConstraint(
   {
     // Several points may be coincident, it is not necessary to store all constraints between them.
     // Try to find sequence of coincident points which connects the points of new constraint
-    if (aConstrType == SLVS_C_POINTS_COINCIDENT &&
-        !addCoincidentPoints(aConstrEnt[0], aConstrEnt[1]))
+    if (aConstrType == SLVS_C_POINTS_COINCIDENT)
     {
-      myExtraCoincidence.insert(theConstraint); // the constraint is stored for further purposes
-      return false;
+      if (aConstrEnt[0] == aConstrEnt[1]) // no need to add self coincidence
+      {
+        return false;
+      }
+      if (!addCoincidentPoints(aConstrEnt[0], aConstrEnt[1]))
+      {
+        myExtraCoincidence.insert(theConstraint); // the constraint is stored for further purposes
+        return false;
+      }
     }
 
     // Create SolveSpace constraint structure