Salome HOME
Create Presentation for rigid constraint
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 24 Oct 2014 09:24:32 +0000 (13:24 +0400)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 24 Oct 2014 09:24:32 +0000 (13:24 +0400)
src/GeomAPI/GeomAPI_AISObject.cpp
src/GeomAPI/GeomAPI_AISObject.h
src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp
src/SketchPlugin/SketchPlugin_ConstraintRigid.h

index 22863757e8a855bdd25058438d88c99c827d74f4..de00d5a436b33a88144ec9e07bca6a0b11ce77f5 100644 (file)
@@ -22,6 +22,7 @@
 #include <AIS_PerpendicularRelation.hxx>
 #include <AIS_RadiusDimension.hxx>
 #include <AIS_Shape.hxx>
+#include <AIS_FixRelation.hxx>
 
 const double tolerance = 1e-7;
 
@@ -219,6 +220,30 @@ void GeomAPI_AISObject::createPerpendicular(boost::shared_ptr<GeomAPI_Shape> the
   }
 }
 
+
+void GeomAPI_AISObject::createFixed(boost::shared_ptr<GeomAPI_Shape> theShape,
+                                    boost::shared_ptr<GeomAPI_Pln> thePlane)
+{
+  Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl<gp_Pln>());
+  Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
+  if (anAIS.IsNull()) {
+    Handle(AIS_FixRelation) aFixPrs = 
+      new AIS_FixRelation(theShape->impl<TopoDS_Shape>(), aPlane);
+
+    setImpl(new Handle(AIS_InteractiveObject)(aFixPrs));
+  } else {
+    Handle(AIS_PerpendicularRelation) aFixPrs = 
+      Handle(AIS_PerpendicularRelation)::DownCast(anAIS);
+    if (!aFixPrs.IsNull()) {
+      aFixPrs->SetFirstShape(theShape->impl<TopoDS_Shape>());
+      aFixPrs->SetPlane(aPlane);
+      aFixPrs->Redisplay(Standard_True);
+    }
+  }
+}
+
+
+
 void GeomAPI_AISObject::setColor(const int& theColor)
 {
   Handle(AIS_InteractiveObject) anAIS = impl<Handle(AIS_InteractiveObject)>();
index 574d39f137c26ed6688c73c77f830cc077eea80e..0c8034d0dd8038875e1baefb3053c96bf7c03bb3 100644 (file)
@@ -77,6 +77,13 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface
                            boost::shared_ptr<GeomAPI_Shape> theLine2,
                            boost::shared_ptr<GeomAPI_Pln> thePlane);
 
+  /** \brief Creates AIS_FixedRelation object for an object
+   *  \param[in] theShape       the object
+   *  \param[in] thePlane       the plane which contains the lines
+   */
+  void createFixed(boost::shared_ptr<GeomAPI_Shape> theShape,
+                   boost::shared_ptr<GeomAPI_Pln> thePlane);
+
   /** \brief Assigns the color for the shape
    *  \param[in] theColor index of the color
    */
index b1cd1708bfbab8a93da24c2f25707b3c4748fdee..c9763327e2b6f23f97452473eef478a45c902b2a 100644 (file)
@@ -4,6 +4,8 @@
 
 #include "SketchPlugin_ConstraintRigid.h"
 
+#include <ModelAPI_ResultConstruction.h>
+
 SketchPlugin_ConstraintRigid::SketchPlugin_ConstraintRigid()
 {
 }
@@ -16,3 +18,37 @@ void SketchPlugin_ConstraintRigid::initAttributes()
 void SketchPlugin_ConstraintRigid::execute()
 {
 }
+
+AISObjectPtr SketchPlugin_ConstraintRigid::getAISObject(AISObjectPtr thePrevious)
+{
+  if (!sketch())
+    return thePrevious;
+
+  boost::shared_ptr<ModelAPI_Data> aData = data();
+  boost::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = boost::dynamic_pointer_cast<
+      ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
+  if (!anAttr || !anAttr->isObject())
+    return thePrevious;
+
+  boost::shared_ptr<ModelAPI_ResultConstruction> aConst = 
+    boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(anAttr->object());
+  if (!aConst) 
+    return thePrevious;
+
+  boost::shared_ptr<GeomAPI_Shape> aShape;
+  aShape = aConst->shape();
+
+  AISObjectPtr anAIS = thePrevious;
+  if (!anAIS)
+    anAIS = AISObjectPtr(new GeomAPI_AISObject);
+
+  boost::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
+  anAIS->createFixed(aShape, aPlane);
+
+  // Set color from preferences
+  //std::vector<int> aRGB = Config_PropManager::color("Visualization", "perpendicular_color",
+  //                                                  PERPENDICULAR_COLOR);
+  //anAIS->setColor(aRGB[0], aRGB[1], aRGB[2]);
+
+  return anAIS;
+}
\ No newline at end of file
index dd66a6f636f4f2b734f976ffedce5a131673d42b..8816ea4b632d9658bb38748db79b24e0a3e3fade 100644 (file)
@@ -33,6 +33,9 @@ class SketchPlugin_ConstraintRigid : public SketchPlugin_ConstraintBase
     return MY_KIND;
   }
 
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
   /// \brief Creates a new part document if needed
   SKETCHPLUGIN_EXPORT virtual void execute();