X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintPerpendicular.cpp;h=4f6a0b77136a4e5ef3794a065b23e310233689ef;hb=3ce4e2cad0e6802282a5a1d10c49c041e8a9f287;hp=ca5e229728e7a777f12c9e00da517b739af8ba2c;hpb=ad3c47dc4fecb938823b3f46edd351a36edc7ee1;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp index ca5e22972..4f6a0b771 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintPerpendicular.cpp @@ -6,11 +6,14 @@ #include #include +#include + #include +#include -#include -#include -#include +#include +#include +#include SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular() { @@ -18,63 +21,69 @@ SketchPlugin_ConstraintPerpendicular::SketchPlugin_ConstraintPerpendicular() void SketchPlugin_ConstraintPerpendicular::initAttributes() { - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); - data()->addAttribute(CONSTRAINT_ATTR_ENTITY_B, ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::type()); + data()->addAttribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT(), GeomDataAPI_Point2D::type()); } void SketchPlugin_ConstraintPerpendicular::execute() { } -const boost::shared_ptr& SketchPlugin_ConstraintPerpendicular::preview() -{ - /// \todo Preview for perpendicular constraint - return getPreview(); -} - -Handle_AIS_InteractiveObject SketchPlugin_ConstraintPerpendicular::getAISShape(Handle_AIS_InteractiveObject thePrevious) +boost::shared_ptr SketchPlugin_ConstraintPerpendicular::getAISObject( + boost::shared_ptr thePrevious) { - Handle(AIS_InteractiveObject) anAIS = thePrevious; if (!sketch()) - return anAIS; + return thePrevious; boost::shared_ptr aData = data(); boost::shared_ptr anAttr1 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_A)); + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); boost::shared_ptr anAttr2 = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_ENTITY_B)); - if (!anAttr1 || !anAttr1->isFeature() || - !anAttr2 || !anAttr2->isFeature()) - return anAIS; + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::ENTITY_B())); + if (!anAttr1 || !anAttr1->isObject() || + !anAttr2 || !anAttr2->isObject()) + return thePrevious; + + FeaturePtr aFeature = ModelAPI_Feature::feature(anAttr1->object()); + if (!aFeature) + return thePrevious; boost::shared_ptr aLine1Feature = - boost::dynamic_pointer_cast(anAttr1->feature()); + boost::dynamic_pointer_cast(aFeature); + + aFeature = ModelAPI_Feature::feature(anAttr2->object()); + if (!aFeature) + return thePrevious; boost::shared_ptr aLine2Feature = - boost::dynamic_pointer_cast(anAttr2->feature()); + boost::dynamic_pointer_cast(aFeature); + if (!aLine1Feature || !aLine2Feature) - return anAIS; - - boost::shared_ptr aLine1 = aLine1Feature->preview(); - boost::shared_ptr aLine2 = aLine2Feature->preview(); - Handle(Geom_Plane) aPlane = new Geom_Plane(sketch()->plane()->impl()); - - if (anAIS.IsNull()) - { - Handle(AIS_PerpendicularRelation) aPerpendicular = - new AIS_PerpendicularRelation(aLine1->impl(), aLine2->impl(), aPlane); - - anAIS = aPerpendicular; - } - else - { - Handle(AIS_PerpendicularRelation) aPerpendicular = Handle(AIS_PerpendicularRelation)::DownCast(anAIS); - if (!aPerpendicular.IsNull()) - { - aPerpendicular->SetFirstShape(aLine1->impl()); - aPerpendicular->SetSecondShape(aLine2->impl()); - aPerpendicular->SetPlane(aPlane); - aPerpendicular->Redisplay(Standard_True); - } - } + return thePrevious; + + boost::shared_ptr aPlane = sketch()->plane(); + boost::shared_ptr aLine1, aLine2; + boost::shared_ptr aConst1 = + boost::dynamic_pointer_cast(anAttr1->object()); + if (aConst1) aLine1 = aConst1->shape(); + boost::shared_ptr aConst2 = + boost::dynamic_pointer_cast(anAttr2->object()); + if (aConst2) aLine2 = aConst2->shape(); + + boost::shared_ptr anAIS = thePrevious; + if (!anAIS) + anAIS = boost::shared_ptr(new GeomAPI_AISObject); + anAIS->createPerpendicular(aLine1, aLine2, aPlane); return anAIS; } +void SketchPlugin_ConstraintPerpendicular::move(double theDeltaX, double theDeltaY) +{ + boost::shared_ptr aData = data(); + if (!aData->isValid()) + return; + + boost::shared_ptr aPoint = + boost::dynamic_pointer_cast(aData->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); + aPoint->setValue(aPoint->x() + theDeltaX, aPoint->y() + theDeltaY); +} +