From 050fbffc14076e3a220135330916a9d77d565631 Mon Sep 17 00:00:00 2001 From: nds Date: Tue, 22 Dec 2015 13:29:16 +0300 Subject: [PATCH] 2D point selection in multi-rotation/multi-translation. --- src/PartSet/CMakeLists.txt | 2 - src/PartSet/PartSet_Module.cpp | 6 -- src/PartSet/PartSet_WidgetPoint2dAngle.cpp | 51 -------------- src/PartSet/PartSet_WidgetPoint2dAngle.h | 47 ------------- .../SketchPlugin_MultiRotation.cpp | 69 +++---------------- src/SketchPlugin/SketchPlugin_MultiRotation.h | 13 +--- .../SketchPlugin_MultiTranslation.cpp | 6 +- src/SketchPlugin/SketchPlugin_Tools.cpp | 53 -------------- src/SketchPlugin/SketchPlugin_Tools.h | 22 ------ src/SketchPlugin/Test/TestMultiRotation.py | 19 ++++- src/SketchPlugin/Test/TestMultiTranslation.py | 12 ++-- src/SketchPlugin/plugin-Sketch.xml | 29 ++++---- src/SketchSolver/SketchSolver_Builder.h | 1 + .../SketchSolver_ConstraintMultiRotation.cpp | 57 +++++++++++++-- .../SketchSolver_ConstraintMultiRotation.h | 10 ++- ...ketchSolver_ConstraintMultiTranslation.cpp | 11 +-- .../SketchSolver_ConstraintMultiTranslation.h | 3 +- .../SolveSpaceSolver_Builder.cpp | 14 +++- .../SolveSpaceSolver_Builder.h | 1 + src/SketcherPrs/CMakeLists.txt | 1 + .../SketcherPrs_Transformation.cpp | 13 ++-- 21 files changed, 137 insertions(+), 303 deletions(-) delete mode 100644 src/PartSet/PartSet_WidgetPoint2dAngle.cpp delete mode 100644 src/PartSet/PartSet_WidgetPoint2dAngle.h diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 05e04db0d..743e937fe 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -15,7 +15,6 @@ SET(PROJECT_HEADERS PartSet_WidgetSketchLabel.h PartSet_Validators.h PartSet_WidgetPoint2d.h - PartSet_WidgetPoint2dAngle.h PartSet_WidgetEditor.h PartSet_WidgetMultiSelector.h PartSet_WidgetPoint2dDistance.h @@ -43,7 +42,6 @@ SET(PROJECT_SOURCES PartSet_WidgetEditor.cpp PartSet_WidgetMultiSelector.cpp PartSet_WidgetPoint2d.cpp - PartSet_WidgetPoint2dAngle.cpp PartSet_WidgetPoint2dDistance.cpp PartSet_WidgetPoint2DFlyout.cpp PartSet_WidgetShapeSelector.cpp diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index ba4ba6680..fb633f631 100755 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -8,7 +8,6 @@ #include "PartSet_WidgetPoint2dDistance.h" #include "PartSet_WidgetPoint2DFlyout.h" #include "PartSet_WidgetShapeSelector.h" -#include "PartSet_WidgetPoint2dAngle.h" #include "PartSet_WidgetMultiSelector.h" #include "PartSet_WidgetEditor.h" #include "PartSet_WidgetFileSelector.h" @@ -512,11 +511,6 @@ ModuleBase_ModelWidget* PartSet_Module::createWidgetByType(const std::string& th aWorkshop, theWidgetApi, theParentId); aDistanceWgt->setSketch(mySketchMgr->activeSketch()); aWgt = aDistanceWgt; - } else if(theType == "point2dangle") { - PartSet_WidgetPoint2dAngle* anAngleWgt = new PartSet_WidgetPoint2dAngle(theParent, - aWorkshop, theWidgetApi, theParentId); - anAngleWgt->setSketch(mySketchMgr->activeSketch()); - aWgt = anAngleWgt; } else if (theType == "sketch_shape_selector") { PartSet_WidgetShapeSelector* aShapeSelectorWgt = new PartSet_WidgetShapeSelector(theParent, aWorkshop, theWidgetApi, theParentId); diff --git a/src/PartSet/PartSet_WidgetPoint2dAngle.cpp b/src/PartSet/PartSet_WidgetPoint2dAngle.cpp deleted file mode 100644 index 86c4def18..000000000 --- a/src/PartSet/PartSet_WidgetPoint2dAngle.cpp +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_WidgetPoint2dAngle.cpp -// Created: 23 June 2014 -// Author: Vitaly Smetannikov - -#include "PartSet_WidgetPoint2dAngle.h" - -#include - -#include - -#include -#include - -#include -#include - -#include - -#include -#include - -#define PI 3.1415926535897932 - -PartSet_WidgetPoint2dAngle::PartSet_WidgetPoint2dAngle(QWidget* theParent, - ModuleBase_IWorkshop* theWorkshop, - const Config_WidgetAPI* theData, - const std::string& theParentId) -: PartSet_WidgetPoint2dDistance(theParent, theWorkshop, theData, theParentId) -{ -} - -PartSet_WidgetPoint2dAngle::~PartSet_WidgetPoint2dAngle() -{ -} - -double PartSet_WidgetPoint2dAngle::computeValue(const std::shared_ptr& theFirstPnt, - const std::shared_ptr& theCurrentPnt) -{ - std::shared_ptr aHorizontalDir(new GeomAPI_Dir2d(1, 0)); - std::shared_ptr aStartPnt = theFirstPnt->xy(); - std::shared_ptr aEndPnt = theCurrentPnt->xy(); - - std::shared_ptr aLineDir(new GeomAPI_Dir2d(aEndPnt->decreased(aStartPnt))); - - double aValue = aHorizontalDir->angle(aLineDir); - aValue *= 180.0 / PI; - - return aValue; -} diff --git a/src/PartSet/PartSet_WidgetPoint2dAngle.h b/src/PartSet/PartSet_WidgetPoint2dAngle.h deleted file mode 100644 index 93e4fdd78..000000000 --- a/src/PartSet/PartSet_WidgetPoint2dAngle.h +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PartSet_WidgetPoint2dAngle.h -// Created: 30 Apr 2015 -// Author: Natalia Ermolaeva - -#ifndef PartSet_WidgetPoint2dAngle_H -#define PartSet_WidgetPoint2dAngle_H - -#include "PartSet.h" -#include "PartSet_WidgetPoint2dDistance.h" - -#include - -class ModuleBase_IWorkshop; - -class GeomAPI_Pnt2d; - -/** -* \ingroup Modules -* Implementation of model widget for widget which provides input of an anble between two points -* The XML definion is the same as the parent one. -*/ -class PARTSET_EXPORT PartSet_WidgetPoint2dAngle : public PartSet_WidgetPoint2dDistance -{ -Q_OBJECT - public: - /// Constructor - /// \param theParent the parent object - /// \param theWorkshop a current workshop - /// \param theData the widget configuation. The attribute of the model widget is obtained from - /// \param theParentId is Id of a parent of the current attribute - PartSet_WidgetPoint2dAngle(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, - const Config_WidgetAPI* theData, const std::string& theParentId); - - virtual ~PartSet_WidgetPoint2dAngle(); - -protected: - /// Compute an angle between points - /// \param theFirstPnt a point value of the out point attribute - /// \param theCurrentPnt a point of the current widget - /// \return a double value - virtual double computeValue(const std::shared_ptr& theFirstPnt, - const std::shared_ptr& theCurrentPnt); -}; - -#endif diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp index bd7fec21f..e878ea50d 100755 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp @@ -8,6 +8,7 @@ #include "SketchPlugin_Tools.h" #include +#include #include #include #include @@ -28,17 +29,15 @@ #define PI 3.1415926535897932 SketchPlugin_MultiRotation::SketchPlugin_MultiRotation() -: myBlockAngle(false) { } void SketchPlugin_MultiRotation::initAttributes() { - data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::typeId()); + data()->addAttribute(CENTER_ID(), ModelAPI_AttributeRefAttr::typeId()); data()->addAttribute(ANGLE_TYPE(), ModelAPI_AttributeString::typeId()); data()->addAttribute(ANGLE_ID(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(ANGLE_FULL_ID(), ModelAPI_AttributeDouble::typeId()); data()->addAttribute(NUMBER_OF_OBJECTS_ID(), ModelAPI_AttributeInteger::typeId()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefList::typeId()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId()); @@ -61,26 +60,15 @@ void SketchPlugin_MultiRotation::execute() return; // Obtain center and angle of rotation - std::shared_ptr aCenter = std::dynamic_pointer_cast( - attribute(CENTER_ID())); + AttributeRefAttrPtr aCenter = data()->refattr(CENTER_ID()); if (!aCenter || !aCenter->isInitialized()) return; - if (attribute(ANGLE_ID())->isInitialized() && !attribute(ANGLE_FULL_ID())->isInitialized()) { - myBlockAngle = true; - SketchPlugin_Tools::updateMultiAttribute(attribute(ANGLE_ID()), attribute(ANGLE_FULL_ID()), - aNbCopies, true); - myBlockAngle = false; - } - - // make a visible points - SketchPlugin_Sketch::createPoint2DResult(this, sketch(), CENTER_ID(), 0); - - double anAngle = std::dynamic_pointer_cast( - attribute(ANGLE_ID()))->value(); + //double anAngle = std::dynamic_pointer_cast( + // attribute(ANGLE_ID()))->value(); // Convert angle to radians - anAngle *= PI / 180.0; + //anAngle *= PI / 180.0; // Wait all objects being created, then send update events static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); @@ -250,7 +238,7 @@ ObjectPtr SketchPlugin_MultiRotation::copyFeature(ObjectPtr theObject) return ObjectPtr(); } -void SketchPlugin_MultiRotation::rotateFeature( +/*void SketchPlugin_MultiRotation::rotateFeature( ObjectPtr theInitial, ObjectPtr theTarget, double theCenterX, double theCenterY, double theAngle) { @@ -288,7 +276,7 @@ void SketchPlugin_MultiRotation::rotateFeature( // unblock feature update aTargetFeature->data()->blockSendAttributeUpdated(false); -} +}*/ void SketchPlugin_MultiRotation::attributeChanged(const std::string& theID) @@ -325,45 +313,4 @@ void SketchPlugin_MultiRotation::attributeChanged(const std::string& theID) data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear(); } } - else if (theID == ANGLE_ID() && !myBlockAngle) { - int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; - if (aNbCopies > 0) { - myBlockAngle = true; - SketchPlugin_Tools::updateMultiAttribute(attribute(ANGLE_ID()), attribute(ANGLE_FULL_ID()), - aNbCopies, true); - myBlockAngle = false; - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - } - } - else if (theID == ANGLE_FULL_ID() && !myBlockAngle) { - int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; - if (aNbCopies > 0) { - myBlockAngle = true; - SketchPlugin_Tools::updateMultiAttribute(attribute(ANGLE_FULL_ID()), attribute(ANGLE_ID()), - aNbCopies, false); - myBlockAngle = false; - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - } - } - else if (theID == NUMBER_OF_OBJECTS_ID()) { - if (attribute(NUMBER_OF_OBJECTS_ID())->isInitialized() && - attribute(ANGLE_ID())->isInitialized() && - attribute(ANGLE_TYPE())->isInitialized()) { - AttributeStringPtr aMethodTypeAttr = string(ANGLE_TYPE()); - std::string aMethodType = aMethodTypeAttr->value(); - int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1; - if (aNbCopies > 0) { - myBlockAngle = true; - if (aMethodType == "SingleAngle") - SketchPlugin_Tools::updateMultiAttribute(attribute(ANGLE_ID()), attribute(ANGLE_FULL_ID()), - aNbCopies, true); - else { - SketchPlugin_Tools::updateMultiAttribute(attribute(ANGLE_FULL_ID()), attribute(ANGLE_ID()), - aNbCopies, false); - } - myBlockAngle = false; - Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); - } - } - } } diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.h b/src/SketchPlugin/SketchPlugin_MultiRotation.h index 416f477b1..97528ebc0 100644 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.h +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.h @@ -65,12 +65,6 @@ class SketchPlugin_MultiRotation : public SketchPlugin_ConstraintBase static const std::string MY_ANGLE_ID("MultiRotationAngle"); return MY_ANGLE_ID; } - /// End point of translation - inline static const std::string& ANGLE_FULL_ID() - { - static const std::string MY_ANGLE_FULL_ID("MultiRotationFullAngle"); - return MY_ANGLE_FULL_ID; - } /// Total number of objects, initial and translated objects inline static const std::string& NUMBER_OF_OBJECTS_ID() @@ -97,13 +91,10 @@ class SketchPlugin_MultiRotation : public SketchPlugin_ConstraintBase private: ObjectPtr copyFeature(ObjectPtr theObject); - void rotateFeature(ObjectPtr theInitial, ObjectPtr theTarget, - double theCenterX, double theCenterY, double theAngle); + //void rotateFeature(ObjectPtr theInitial, ObjectPtr theTarget, + // double theCenterX, double theCenterY, double theAngle); bool updateFullAngleValue(); - -private: - bool myBlockAngle; /// a boolean state to avoid recusive angle change in attributeChanged }; #endif diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp index bc4a16755..df1643454 100755 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp @@ -62,10 +62,8 @@ void SketchPlugin_MultiTranslation::execute() return; DataPtr aData = data(); - std::shared_ptr aStart = GeomDataAPI_Point2D::getPoint2D(aData, - START_POINT_ID()); - std::shared_ptr aEnd = GeomDataAPI_Point2D::getPoint2D(aData, - END_POINT_ID()); + AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData, START_POINT_ID()); + AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData, END_POINT_ID()); if (!aStart || !aEnd) return; diff --git a/src/SketchPlugin/SketchPlugin_Tools.cpp b/src/SketchPlugin/SketchPlugin_Tools.cpp index a9aa9d90c..82c5a3f93 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.cpp +++ b/src/SketchPlugin/SketchPlugin_Tools.cpp @@ -101,57 +101,4 @@ void findCoincidences(const FeaturePtr theStartCoin, } } -void updateMultiAttribute(const AttributePtr& theFirstAngleAttribute, - const AttributePtr& theSecondAngleAttribute, - const int& theValue, - const bool toMultiply) -{ - if (theValue == 0 || !theFirstAngleAttribute->isInitialized()) - return; - - AttributeDoublePtr aDoubleFirstAttr = std::dynamic_pointer_cast( - theFirstAngleAttribute); - double aValue = aDoubleFirstAttr->value(); - - AttributeDoublePtr aDoubleSecondAttr = std::dynamic_pointer_cast( - theSecondAngleAttribute); - if (toMultiply) - aDoubleSecondAttr->setValue(aValue*theValue); - else - aDoubleSecondAttr->setValue(aValue/theValue); -} - -void updateMultiAttribute(const AttributePtr& theFirstAttribute, - const AttributePtr& theSecondAttribute, - const AttributePtr& theModifiedAttribute, - const int& theValue, - const bool toMultiply) -{ - if (theValue == 0 || !theFirstAttribute->isInitialized() - || !theSecondAttribute->isInitialized()) - return; - - std::shared_ptr aFirstPoint = - std::dynamic_pointer_cast(theFirstAttribute); - std::shared_ptr aSecondPoint = - std::dynamic_pointer_cast(theSecondAttribute); - std::shared_ptr aModifiedPoint = - std::dynamic_pointer_cast(theModifiedAttribute); - - if (!aFirstPoint.get() || !aSecondPoint.get() || !aModifiedPoint.get()) - return; - - if (aFirstPoint->pnt()->isEqual(aSecondPoint->pnt())) - aModifiedPoint->setValue(aFirstPoint->pnt()); - else { - double aDx = aSecondPoint->x() - aFirstPoint->x(); - double aDy = aSecondPoint->y() - aFirstPoint->y(); - - double aX = toMultiply ? aDx * theValue : aDx / theValue; - double anY = toMultiply ? aDy * theValue : aDy / theValue; - - aModifiedPoint->setValue(aFirstPoint->x() + aX, aFirstPoint->y() + anY); - } -} - } // namespace SketchPlugin_Tools diff --git a/src/SketchPlugin/SketchPlugin_Tools.h b/src/SketchPlugin/SketchPlugin_Tools.h index 6b242532b..32dfbb129 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.h +++ b/src/SketchPlugin/SketchPlugin_Tools.h @@ -28,28 +28,6 @@ std::shared_ptr getCoincidencePoint(const FeaturePtr theStartCoin void findCoincidences(const FeaturePtr theStartCoin, const std::string& theAttr, std::set& theList); - -/// Changes the second attribute value to be multiplied or divided by the given value. -/// \param theFirstAngleAttribute the source attribute -/// \param theSecondAngleAttribute the changed attribute -/// \param theValue a value for modification -/// \param toMultiply a type of modification -void updateMultiAttribute(const AttributePtr& theFirstAngleAttribute, - const AttributePtr& theSecondAngleAttribute, - const int& theValue, - const bool toMultiply); - -/// Changes the second attribute value to be multiplied or divided by the given value. -/// \param theFirstAngleAttribute the source attribute -/// \param theSecondAngleAttribute the changed attribute -/// \param theValue a value for modification -/// \param toMultiply a type of modification -void updateMultiAttribute(const AttributePtr& theFirstAttribute, - const AttributePtr& theSecondAttribute, - const AttributePtr& theModifiedAttribute, - const int& theValue, - const bool toMultiply); - }; // namespace SketchPlugin_Tools #endif // SKETCHPLUGIN_TOOLS_H_ \ No newline at end of file diff --git a/src/SketchPlugin/Test/TestMultiRotation.py b/src/SketchPlugin/Test/TestMultiRotation.py index 68a3b6a39..34cb0387f 100644 --- a/src/SketchPlugin/Test/TestMultiRotation.py +++ b/src/SketchPlugin/Test/TestMultiRotation.py @@ -112,6 +112,14 @@ CENTER_X = 0. CENTER_Y = 0. ANGLE = 30. #========================================================================= +# Create rotation point +#========================================================================= +aSession.startOperation() +aRotationPoint = aSketchFeature.addFeature("SketchPoint") +aRotationPointPoint = geomDataAPI_Point2D(aRotationPoint.attribute("PointCoordindates")) +aRotationPointPoint.setValue(CENTER_X, CENTER_Y) +aSession.finishOperation() +#========================================================================= # Create the Rotation constraint #========================================================================= aSession.startOperation() @@ -125,12 +133,17 @@ for aFeature in aFeaturesList: aValueType = aMultiRotation.string("AngleType") aValueType.setValue("SingleValue") -aCenter = geomDataAPI_Point2D(aMultiRotation.attribute("MultiRotationCenter")) +aCenter = aMultiRotation.refattr("MultiRotationCenter") +aCenter.setAttr(aRotationPointPoint) + anAngle = aMultiRotation.real("MultiRotationAngle") -aCenter.setValue(CENTER_X, CENTER_Y) anAngle.setValue(ANGLE) + +anAngle = aMultiRotation.string("AngleType") +anAngle.setValue("SingleAngle") + aNbCopies = aMultiRotation.integer("MultiRotationObjects") -aNbCopies.setValue(1) +aNbCopies.setValue(2) aMultiRotation.execute() aSession.finishOperation() #========================================================================= diff --git a/src/SketchPlugin/Test/TestMultiTranslation.py b/src/SketchPlugin/Test/TestMultiTranslation.py index 633304846..4dca56c49 100644 --- a/src/SketchPlugin/Test/TestMultiTranslation.py +++ b/src/SketchPlugin/Test/TestMultiTranslation.py @@ -60,12 +60,12 @@ def checkTranslation(theObjects, theNbObjects, theDeltaX, theDeltaY): anAttributes.append('ArcStartPoint') anAttributes.append('ArcEndPoint') - #for attr in anAttributes: - #aPoint1 = geomDataAPI_Point2D(feat.attribute(attr)) - #aPoint2 = geomDataAPI_Point2D(next.attribute(attr)) - #aDiffX = aPoint2.x() - aPoint1.x() - theDeltaX - #aDiffY = aPoint2.y() - aPoint1.y() - theDeltaY - #assert(aDiffX**2 + aDiffY**2 < 1.e-15) + for attr in anAttributes: + aPoint1 = geomDataAPI_Point2D(feat.attribute(attr)) + aPoint2 = geomDataAPI_Point2D(next.attribute(attr)) + aDiffX = aPoint2.x() - aPoint1.x() - theDeltaX + aDiffY = aPoint2.y() - aPoint1.y() - theDeltaY + assert(aDiffX**2 + aDiffY**2 < 1.e-15) # Check the number of copies is as planed assert(anInd == theNbObjects-1) diff --git a/src/SketchPlugin/plugin-Sketch.xml b/src/SketchPlugin/plugin-Sketch.xml index eaf7601d3..3ea9cd2ca 100644 --- a/src/SketchPlugin/plugin-Sketch.xml +++ b/src/SketchPlugin/plugin-Sketch.xml @@ -294,7 +294,6 @@ label="Start point" tooltip="Start point of translation" shape_types="vertex"> - @@ -303,7 +302,6 @@ label="End point" tooltip="Final point of translation" shape_types="vertex"> - @@ -316,7 +314,6 @@ label="Start point" tooltip="Start point of translation" shape_types="vertex"> - @@ -325,7 +322,6 @@ label="End point" tooltip="Final point of translation" shape_types="vertex"> - @@ -352,26 +348,27 @@ use_external="true"> - + + + - + default="90" use_reset="false"/> - + tooltip="Rotation angle" + default="90" use_reset="false"/> & theTrsfEnt) const = 0; diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp index 597d313eb..5fc487e12 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.cpp @@ -4,10 +4,13 @@ #include +#include + #include void SketchSolver_ConstraintMultiRotation::getAttributes( EntityWrapperPtr& theCenter, double& theAngle, + bool& theFullValue, std::list< std::list >& theEntities) { DataPtr aData = myBaseConstraint->data(); @@ -25,6 +28,9 @@ void SketchSolver_ConstraintMultiRotation::getAttributes( myStorage->update(aCenterAttr, GID_OUTOFGROUP); theCenter = myStorage->entity(aCenterAttr); + AttributeStringPtr aMethodTypeAttr = aData->string(SketchPlugin_MultiRotation::ANGLE_TYPE()); + theFullValue = aMethodTypeAttr->value() != "SingleAngle"; + getEntitiesAndCopies(theEntities); } @@ -37,8 +43,9 @@ void SketchSolver_ConstraintMultiRotation::process() } EntityWrapperPtr aRotationCenter; + bool isFullValue; std::list > anEntitiesAndCopies; - getAttributes(aRotationCenter, myAngle, anEntitiesAndCopies); + getAttributes(aRotationCenter, myAngle, isFullValue, anEntitiesAndCopies); if (!myErrorMsg.empty()) return; @@ -49,7 +56,7 @@ void SketchSolver_ConstraintMultiRotation::process() for (; anEntIt != anEntitiesAndCopies.end(); ++anEntIt) { std::list aNewConstraints = aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID, myType, - myAngle, aRotationCenter, EntityWrapperPtr(), *anEntIt); + myAngle, isFullValue, aRotationCenter, EntityWrapperPtr(), *anEntIt); aRotConstraints.insert(aRotConstraints.end(), aNewConstraints.begin(), aNewConstraints.end()); } myStorage->addConstraint(myBaseConstraint, aRotConstraints); @@ -68,9 +75,49 @@ void SketchSolver_ConstraintMultiRotation::updateLocal() myAngle = aValue; // update center - AttributePtr aCenterAttr = myBaseConstraint->attribute(SketchPlugin_MultiRotation::CENTER_ID()); - if (myStorage->update(aCenterAttr, myGroupID)) { - myStorage->update(aCenterAttr, GID_UNKNOWN); + DataPtr aData = myBaseConstraint->data(); + AttributePoint2DPtr aCenterPointAttribute = GeomDataAPI_Point2D::getPoint2D(aData, + SketchPlugin_MultiRotation::CENTER_ID()); + bool aCenterPointChanged = aCenterPointAttribute != myCenterPointAttribute; + if (aCenterPointChanged) + myCenterPointAttribute = aCenterPointAttribute; + + AttributeStringPtr aMethodTypeAttr = aData->string(SketchPlugin_MultiRotation::ANGLE_TYPE()); + bool aFullValue = aMethodTypeAttr->value() != "SingleAngle"; + bool isMethodChanged = aFullValue != myIsFullValue; + if (isMethodChanged) + myIsFullValue = aFullValue; + + if (aCenterPointChanged || isMethodChanged) { + DataPtr aData = myBaseConstraint->data(); + std::list aConstraints = myStorage->constraint(myBaseConstraint); + std::list::const_iterator anIt = aConstraints.begin(), + aLast = aConstraints.end(); + std::list anEntities; + for (; anIt != aLast; anIt++) { + ConstraintWrapperPtr aConstraint = *anIt; + aConstraint->setIsFullValue(myIsFullValue); + if (aCenterPointChanged) { + anEntities.clear(); + const std::list& aConstraintEntities = aConstraint->entities(); + std::list::const_iterator aSIt = aConstraintEntities.begin(), + aSLast = aConstraintEntities.end(); + EntityWrapperPtr aCenterPointEntity = *aSIt++; + if (aCenterPointChanged) { + AttributePtr aCenterPointAttr = aData->attribute(SketchPlugin_MultiRotation::CENTER_ID()); + myStorage->update(aCenterPointAttr); + aCenterPointEntity = myStorage->entity(aCenterPointAttr); + } + anEntities.push_back(aCenterPointEntity); + + for (; aSIt != aSLast; ++aSIt) + anEntities.push_back(*aSIt); + + aConstraint->setEntities(anEntities); + } + } + myStorage->addConstraint(myBaseConstraint, aConstraints); + myAdjusted = false; } } diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h index 6aad12d63..6d241f92d 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h +++ b/src/SketchSolver/SketchSolver_ConstraintMultiRotation.h @@ -10,6 +10,8 @@ #include "SketchSolver.h" #include +#include "GeomDataAPI_Point2D.h" + /** \class SketchSolver_ConstraintMultiRotation * \ingroup Plugins * \brief Convert rotated features to the list of SolveSpace constraints @@ -29,8 +31,9 @@ protected: /// \brief Generate list of rotated entities /// \param[out] theCenter central point of rotation /// \param[out] theAngle rotation angle + /// \param[out] theFullValue applying translation using the disstance as a full or single value /// \param[out] theEntities list of entities and their rotated copies - void getAttributes(EntityWrapperPtr& theCenter, double& theAngle, + void getAttributes(EntityWrapperPtr& theCenter, double& theAngle, bool& theFullValue, std::list< std::list >& theEntities); /// \brief This method is used in derived objects to check consistence of constraint. @@ -42,7 +45,10 @@ protected: private: /// \brief Returns name of NUMBER_OF_COPIES parameter for corresponding feature virtual const std::string& nameNbObjects(); - double myAngle; ///< angle of rotation + + AttributePoint2DPtr myCenterPointAttribute; ///< a center of rotation + double myAngle; ///< angle of rotation + bool myIsFullValue; ///< value whether the angle is a full or single for objects }; #endif diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp index dd4bbb0d8..d5a08f069 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.cpp @@ -10,7 +10,7 @@ void SketchSolver_ConstraintMultiTranslation::getAttributes( EntityWrapperPtr& theStartPoint, EntityWrapperPtr& theEndPoint, - std::list< std::list >& theEntities) + bool& theFullValue, std::list< std::list >& theEntities) { DataPtr aData = myBaseConstraint->data(); AttributePtr aStartPointAttr = aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID()); @@ -28,8 +28,10 @@ void SketchSolver_ConstraintMultiTranslation::getAttributes( myStorage->update(aEndPointAttr); theEndPoint = myStorage->entity(aEndPointAttr); - getEntitiesAndCopies(theEntities); + AttributeStringPtr aMethodTypeAttr = aData->string(SketchPlugin_MultiTranslation::VALUE_TYPE()); + theFullValue = aMethodTypeAttr->value() != "SingleValue"; + getEntitiesAndCopies(theEntities); } void SketchSolver_ConstraintMultiTranslation::process() @@ -41,8 +43,9 @@ void SketchSolver_ConstraintMultiTranslation::process() } EntityWrapperPtr aStartPoint, aEndPoint; + bool aFullValue; std::list > anEntitiesAndCopies; - getAttributes(aStartPoint, aEndPoint, anEntitiesAndCopies); + getAttributes(aStartPoint, aEndPoint, aFullValue, anEntitiesAndCopies); if (!myErrorMsg.empty()) return; @@ -58,7 +61,7 @@ void SketchSolver_ConstraintMultiTranslation::process() for (; anEntIt != anEntitiesAndCopies.end(); ++anEntIt) { std::list aNewConstraints = aBuilder->createConstraint(myBaseConstraint, myGroupID, mySketchID, myType, - 0.0, aStartPoint, aEndPoint, *anEntIt); + 0.0, aFullValue, aStartPoint, aEndPoint, *anEntIt); aTransConstraints.insert(aTransConstraints.end(), aNewConstraints.begin(), aNewConstraints.end()); } std::list::iterator aTCIt = aTransConstraints.begin(); diff --git a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h index a0f6ca525..ef9938a9c 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h +++ b/src/SketchSolver/SketchSolver_ConstraintMultiTranslation.h @@ -31,9 +31,10 @@ protected: /// \brief Generate list of translated entities /// \param[out] theStartPoint start point of translation /// \param[out] theEndPoint final point of translation + /// \param[out] theFullValue applying translation using the disstance as a full or single value /// \param[out] theEntities list of entities and their translated copies void getAttributes(EntityWrapperPtr& theStartPoint, EntityWrapperPtr& theEndPoint, - std::list< std::list >& theEntities); + bool& theFullValue, std::list< std::list >& theEntities); /// \brief Update parameters (called from base class) virtual void updateLocal(); diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp index 5e1b85015..9b1105e24 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.cpp @@ -134,6 +134,7 @@ std::list SolveSpaceSolver_Builder::createConstraint( const EntityID& theSketchID, const SketchSolver_ConstraintType& theType, const double& theValue, + const bool& theFullValue, const EntityWrapperPtr& thePoint1, const EntityWrapperPtr& thePoint2, const std::list& theTrsfEnt) const @@ -156,6 +157,7 @@ std::list SolveSpaceSolver_Builder::createConstraint( ConstraintWrapperPtr aResult(new SolveSpaceSolver_ConstraintWrapper(theConstraint, aConstraint)); aResult->setValue(theValue); + aResult->setIsFullValue(theFullValue); aResult->setEntities(aConstrAttrList); return std::list(1, aResult); } @@ -812,11 +814,19 @@ void adjustMultiRotation(ConstraintWrapperPtr theConstraint) { BuilderPtr aBuilder = SolveSpaceSolver_Builder::getInstance(); - double anAngleRad = theConstraint->value() * PI / 180.0; + double anAngleValue = theConstraint->value(); + const std::list& aSubs = theConstraint->entities(); + + bool isFullValue = theConstraint->isFullValue(); + int aNbObjects = aSubs.size()-2; + if (isFullValue && aNbObjects > 0) { + anAngleValue /= aNbObjects; + } + + double anAngleRad = anAngleValue * PI / 180.0; double aSin = sin(anAngleRad); double aCos = cos(anAngleRad); - const std::list& aSubs = theConstraint->entities(); std::list::const_iterator aSIt = aSubs.begin(); std::shared_ptr aCenter = aBuilder->point(*aSIt++); diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.h b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.h index f55330ad2..2f8e61be9 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.h +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Builder.h @@ -72,6 +72,7 @@ public: const EntityID& theSketchID, const SketchSolver_ConstraintType& theType, const double& theValue, + const bool& theFullValue, const EntityWrapperPtr& thePoint1, const EntityWrapperPtr& thePoint2, const std::list& theTrsfEnt) const; diff --git a/src/SketcherPrs/CMakeLists.txt b/src/SketcherPrs/CMakeLists.txt index 3c2b87cf5..148f332ad 100644 --- a/src/SketcherPrs/CMakeLists.txt +++ b/src/SketcherPrs/CMakeLists.txt @@ -50,6 +50,7 @@ SET(PROJECT_LIBRARIES Config ModelAPI GeomAPI + GeomDataAPI Events ${CAS_KERNEL} ${CAS_MODELER} diff --git a/src/SketcherPrs/SketcherPrs_Transformation.cpp b/src/SketcherPrs/SketcherPrs_Transformation.cpp index 929148d60..8639c3bb0 100644 --- a/src/SketcherPrs/SketcherPrs_Transformation.cpp +++ b/src/SketcherPrs/SketcherPrs_Transformation.cpp @@ -88,11 +88,11 @@ void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& the drawListOfShapes(anAttrB, thePrs); if (myConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) { // If it is translation - std::shared_ptr aStart = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID())); - std::shared_ptr aEnd = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_MultiTranslation::END_POINT_ID())); - + AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData, + SketchPlugin_MultiTranslation::START_POINT_ID()); + AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData, + SketchPlugin_MultiTranslation::END_POINT_ID()); + if (aStart.get() && aEnd.get() && aStart->isInitialized() && aEnd->isInitialized()) { // Add start point std::shared_ptr aPnt = myPlane->to3D(aStart->x(), aStart->y()); @@ -106,8 +106,7 @@ void SketcherPrs_Transformation::drawLines(const Handle(Prs3d_Presentation)& the } } else if (myConstraint->getKind() == SketchPlugin_MultiRotation::ID()) { // if it is rotation - std::shared_ptr aCenter = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_MultiRotation::CENTER_ID())); + AttributePoint2DPtr aCenter = GeomDataAPI_Point2D::getPoint2D(aData, SketchPlugin_MultiRotation::CENTER_ID()); if (aCenter.get() && aCenter->isInitialized()) { // Show center of rotation std::shared_ptr aPnt = myPlane->to3D(aCenter->x(), aCenter->y()); -- 2.39.2