From: vsv Date: Fri, 24 Oct 2014 09:24:32 +0000 (+0400) Subject: Create Presentation for rigid constraint X-Git-Tag: V_0.5~79^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=43780ffac779af7f061513b0f6243f2edb73602c;p=modules%2Fshaper.git Create Presentation for rigid constraint --- diff --git a/src/GeomAPI/GeomAPI_AISObject.cpp b/src/GeomAPI/GeomAPI_AISObject.cpp index 22863757e..de00d5a43 100644 --- a/src/GeomAPI/GeomAPI_AISObject.cpp +++ b/src/GeomAPI/GeomAPI_AISObject.cpp @@ -22,6 +22,7 @@ #include #include #include +#include const double tolerance = 1e-7; @@ -219,6 +220,30 @@ void GeomAPI_AISObject::createPerpendicular(boost::shared_ptr the } } + +void GeomAPI_AISObject::createFixed(boost::shared_ptr theShape, + boost::shared_ptr thePlane) +{ + Handle(Geom_Plane) aPlane = new Geom_Plane(thePlane->impl()); + Handle(AIS_InteractiveObject) anAIS = impl(); + if (anAIS.IsNull()) { + Handle(AIS_FixRelation) aFixPrs = + new AIS_FixRelation(theShape->impl(), aPlane); + + setImpl(new Handle(AIS_InteractiveObject)(aFixPrs)); + } else { + Handle(AIS_PerpendicularRelation) aFixPrs = + Handle(AIS_PerpendicularRelation)::DownCast(anAIS); + if (!aFixPrs.IsNull()) { + aFixPrs->SetFirstShape(theShape->impl()); + aFixPrs->SetPlane(aPlane); + aFixPrs->Redisplay(Standard_True); + } + } +} + + + void GeomAPI_AISObject::setColor(const int& theColor) { Handle(AIS_InteractiveObject) anAIS = impl(); diff --git a/src/GeomAPI/GeomAPI_AISObject.h b/src/GeomAPI/GeomAPI_AISObject.h index 574d39f13..0c8034d0d 100644 --- a/src/GeomAPI/GeomAPI_AISObject.h +++ b/src/GeomAPI/GeomAPI_AISObject.h @@ -77,6 +77,13 @@ class GEOMAPI_EXPORT GeomAPI_AISObject : public GeomAPI_Interface boost::shared_ptr theLine2, boost::shared_ptr 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 theShape, + boost::shared_ptr thePlane); + /** \brief Assigns the color for the shape * \param[in] theColor index of the color */ diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp index b1cd1708b..c9763327e 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRigid.cpp @@ -4,6 +4,8 @@ #include "SketchPlugin_ConstraintRigid.h" +#include + 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 aData = data(); + boost::shared_ptr anAttr = boost::dynamic_pointer_cast< + ModelAPI_AttributeRefAttr>(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); + if (!anAttr || !anAttr->isObject()) + return thePrevious; + + boost::shared_ptr aConst = + boost::dynamic_pointer_cast(anAttr->object()); + if (!aConst) + return thePrevious; + + boost::shared_ptr aShape; + aShape = aConst->shape(); + + AISObjectPtr anAIS = thePrevious; + if (!anAIS) + anAIS = AISObjectPtr(new GeomAPI_AISObject); + + boost::shared_ptr aPlane = sketch()->plane(); + anAIS->createFixed(aShape, aPlane); + + // Set color from preferences + //std::vector 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 diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRigid.h b/src/SketchPlugin/SketchPlugin_ConstraintRigid.h index dd66a6f63..8816ea4b6 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRigid.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintRigid.h @@ -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();