From: nds Date: Tue, 24 Jun 2014 15:37:52 +0000 (+0400) Subject: refs #80 - Sketch base GUI: create/draw point, circle and arc X-Git-Tag: V_0.4.4~252 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=14d3980515c46076881ff80812f2c1e151211083;p=modules%2Fshaper.git refs #80 - Sketch base GUI: create/draw point, circle and arc Length constraint. --- diff --git a/src/ModuleBase/ModuleBase_WidgetEditor.cpp b/src/ModuleBase/ModuleBase_WidgetEditor.cpp index f62eae3d3..afffeeae4 100644 --- a/src/ModuleBase/ModuleBase_WidgetEditor.cpp +++ b/src/ModuleBase/ModuleBase_WidgetEditor.cpp @@ -31,15 +31,13 @@ ModuleBase_WidgetEditor::ModuleBase_WidgetEditor(QWidget* theParent, ModuleBase_WidgetEditor::~ModuleBase_WidgetEditor() { - //delete myEditor; } bool ModuleBase_WidgetEditor::storeValue(FeaturePtr theFeature) const { DataPtr aData = theFeature->data(); AttributeDoublePtr aReal = aData->real(attributeID()); - bool isOk; - if (isOk && aReal->value() != myValue) { + if (aReal->value() != myValue) { aReal->setValue(myValue); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_FEATURE_UPDATED)); } @@ -74,6 +72,7 @@ void ModuleBase_WidgetEditor::focusTo() if (aRes == QDialog::Accepted) myValue = aEditor->text().toDouble(); + emit valuesChanged(); emit focusOutWidget(this); } diff --git a/src/PartSet/PartSet_ConstraintLengthPrs.cpp b/src/PartSet/PartSet_ConstraintLengthPrs.cpp index 4607b732b..9e4140291 100644 --- a/src/PartSet/PartSet_ConstraintLengthPrs.cpp +++ b/src/PartSet/PartSet_ConstraintLengthPrs.cpp @@ -97,9 +97,9 @@ PartSet_SelectionMode PartSet_ConstraintLengthPrs::setPoint(double theX, double if (!aFeatureLin->isRight(aPoint)) aDistance = -aDistance; - AttributeDoublePtr aFlyoutAttr = - boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); - aFlyoutAttr->setValue(aDistance); + //AttributeDoublePtr aFlyoutAttr = + // boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); + //aFlyoutAttr->setValue(aDistance); aMode = SM_DonePoint; } diff --git a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp index 659eff3f8..92caca86b 100644 --- a/src/PartSet/PartSet_ConstraintRadiusPrs.cpp +++ b/src/PartSet/PartSet_ConstraintRadiusPrs.cpp @@ -90,7 +90,7 @@ PartSet_SelectionMode PartSet_ConstraintRadiusPrs::setPoint(double theX, double boost::shared_ptr aPoint = boost::shared_ptr (new GeomAPI_Pnt2d(theX, theY)); - PartSet_Tools::setFeaturePoint(feature(), theX, theY, SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT); + //PartSet_Tools::setFeaturePoint(feature(), theX, theY, SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT); //double aDistance = 40; //AttributeDoublePtr aFlyoutAttr = diff --git a/src/PartSet/PartSet_OperationFeatureCreate.cpp b/src/PartSet/PartSet_OperationFeatureCreate.cpp index a45a85419..5da96ccb9 100644 --- a/src/PartSet/PartSet_OperationFeatureCreate.cpp +++ b/src/PartSet/PartSet_OperationFeatureCreate.cpp @@ -61,9 +61,9 @@ bool PartSet_OperationFeatureCreate::canProcessKind(const std::string& theId) return theId == SKETCH_LINE_KIND || theId == SKETCH_POINT_KIND || theId == SKETCH_CIRCLE_KIND /*|| theId == SKETCH_ARC_KIND*/ || - theId == SKETCH_CONSTRAINT_DISTANCE_KIND /*|| + theId == SKETCH_CONSTRAINT_DISTANCE_KIND || theId == SKETCH_CONSTRAINT_LENGTH_KIND || - theId == SKETCH_CONSTRAINT_RADIUS_KIND || + theId == SKETCH_CONSTRAINT_RADIUS_KIND /*|| theId == SKETCH_CONSTRAINT_PARALLEL_KIND || theId == SKETCH_CONSTRAINT_PERPENDICULAR_KIND*/; } diff --git a/src/SketchPlugin/SketchPlugin_Constraint.h b/src/SketchPlugin/SketchPlugin_Constraint.h index 50abf8636..632243ba6 100644 --- a/src/SketchPlugin/SketchPlugin_Constraint.h +++ b/src/SketchPlugin/SketchPlugin_Constraint.h @@ -32,8 +32,6 @@ const int CONSTRAINT_TEXT_SELECTION_TOLERANCE = 20; /// the text selection toler const std::string CONSTRAINT_ATTR_VALUE("ConstraintValue"); /// The 2D value parameter for the constraint const std::string CONSTRAINT_ATTR_FLYOUT_VALUE_PNT("ConstraintFlyoutValuePnt"); -/// The value parameter for the constraint -const std::string CONSTRAINT_ATTR_FLYOUT_VALUE("ConstraintFlyoutValue"); /// First entity for the constraint const std::string CONSTRAINT_ATTR_ENTITY_A("ConstraintEntityA"); /// Second entity for the constraint diff --git a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp index 6e37f0cbe..ad8eda3a7 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintDistance.cpp @@ -77,9 +77,8 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape( boost::shared_ptr aFeatureLin = boost::shared_ptr(new GeomAPI_Lin2d(aPoint_A->x(), aPoint_A->y(), aPoint_B->x(), aPoint_B->y())); - boost::shared_ptr aResult = aFeatureLin->project(aFlyOutPnt); - double aDistance = aFlyOutPnt->distance(aResult); - + boost::shared_ptr aProjectedPoint = aFeatureLin->project(aFlyOutPnt); + double aDistance = aFlyOutPnt->distance(aProjectedPoint); if (!aFeatureLin->isRight(aFlyOutPnt)) aDistance = -aDistance; double aFlyout = aDistance; @@ -87,16 +86,11 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintDistance::getAISShape( //Build dimension here boost::shared_ptr aPoint1 = sketch()->to3D(aPoint_A->x(), aPoint_A->y()); boost::shared_ptr aPoint2 = sketch()->to3D(aPoint_B->x(), aPoint_B->y()); - if (aFlyout < 0) - aPoint1.swap(aPoint2); // value calculation boost::shared_ptr aValueAttr = boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_VALUE)); double aValue = aValueAttr->value(); - if (aValue == 0) { // TODO! the default value - aValue = aPoint1->distance(aPoint2); - } Handle(AIS_InteractiveObject) anAIS = thePrevious; if (anAIS.IsNull()) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 6e48926c6..7f54f7947 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -12,6 +12,9 @@ #include +#include +#include + #include #include #include @@ -23,13 +26,33 @@ SketchPlugin_ConstraintLength::SketchPlugin_ConstraintLength() void SketchPlugin_ConstraintLength::initAttributes() { data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type()); - data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type()); + //data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type()); data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); } void SketchPlugin_ConstraintLength::execute() { + if (data()->attribute(CONSTRAINT_ATTR_ENTITY_A)->isInitialized() && + !data()->attribute(CONSTRAINT_ATTR_VALUE)->isInitialized()) { + + boost::shared_ptr aRef = + boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_ENTITY_A)); + FeaturePtr aFeature = aRef->feature(); + if (aFeature) { + // set length value + boost::shared_ptr aPoint1 = + boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_START)); + boost::shared_ptr aPoint2 = + boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_END)); + + double aLenght = aPoint1->pnt()->distance(aPoint2->pnt()); + + boost::shared_ptr aValueAttr = + boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_VALUE)); + aValueAttr->setValue(aLenght); + } + } } Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape( @@ -48,10 +71,29 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape( if (!aFeature || aFeature->getKind() != SKETCH_LINE_KIND) return thePrevious; - boost::shared_ptr aFlyoutAttr = - boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); - double aFlyout = aFlyoutAttr->value(); - + //boost::shared_ptr aFlyoutAttr = + // boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE)); + //double aFlyout = aFlyoutAttr->value(); + // fly out calculation + boost::shared_ptr aFlyOutAttr = + boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); + boost::shared_ptr aFlyOutPnt = aFlyOutAttr->pnt(); + + boost::shared_ptr aStartPoint = + boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_START)); + boost::shared_ptr anEndPoint = + boost::dynamic_pointer_cast(aFeature->data()->attribute(LINE_ATTR_END)); + + boost::shared_ptr aFeatureLin = boost::shared_ptr + (new GeomAPI_Lin2d(aStartPoint->x(), aStartPoint->y(), + anEndPoint->x(), anEndPoint->y())); + boost::shared_ptr aProjectedPoint = aFeatureLin->project(aFlyOutPnt); + double aDistance = aFlyOutPnt->distance(aProjectedPoint); + if (!aFeatureLin->isRight(aFlyOutPnt)) + aDistance = -aDistance; + double aFlyout = aDistance; + + // value boost::shared_ptr aValueAttr = boost::dynamic_pointer_cast(data()->attribute(CONSTRAINT_ATTR_VALUE)); double aValue = aValueAttr->value(); @@ -68,8 +110,6 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintLength::getAISShape( //Build dimension here boost::shared_ptr aPoint1 = sketch()->to3D(aPointStart->x(), aPointStart->y()); boost::shared_ptr aPoint2 = sketch()->to3D(aPointEnd->x(), aPointEnd->y()); - if (aFlyout < 0) - aPoint1.swap(aPoint2); Handle(AIS_InteractiveObject) anAIS = thePrevious; if (anAIS.IsNull()) diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp index a57df918b..8cdb822ae 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.cpp @@ -27,13 +27,12 @@ void SketchPlugin_ConstraintRadius::initAttributes() { data()->addAttribute(CONSTRAINT_ATTR_VALUE, ModelAPI_AttributeDouble::type()); data()->addAttribute(CONSTRAINT_ATTR_ENTITY_A, ModelAPI_AttributeRefAttr::type()); - - data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE, ModelAPI_AttributeDouble::type()); - data()->addAttribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT, GeomDataAPI_Point2D::type()); + data()->addAttribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT, GeomDataAPI_Point2D::type()); } void SketchPlugin_ConstraintRadius::execute() { + } Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( @@ -59,7 +58,7 @@ Handle(AIS_InteractiveObject) SketchPlugin_ConstraintRadius::getAISShape( // an anchor point boost::shared_ptr aAnchorAttr = - boost::dynamic_pointer_cast(aData->attribute(SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT)); + boost::dynamic_pointer_cast(aData->attribute(CONSTRAINT_ATTR_FLYOUT_VALUE_PNT)); boost::shared_ptr anAnchor2D = aAnchorAttr->pnt(); boost::shared_ptr anAnchor = sketch()->to3D(anAnchor2D->x(), anAnchor2D->y()); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h index 7af115ce9..4ff63b2e8 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintRadius.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintRadius.h @@ -12,10 +12,6 @@ /// Radius constraint kind const std::string SKETCH_CONSTRAINT_RADIUS_KIND("SketchConstraintRadius"); -/// Start 2D point of the line -const std::string SKETCH_CONSTRAINT_ATTR_CIRCLE_POINT("CirclePoint"); - - /** \class SketchPlugin_ConstraintRadius * \ingroup DataModel * \brief Feature for creation of a new constraint which defines diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index 8cff21c49..c4bbaab49 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -38,7 +38,7 @@