X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_Tools.cpp;h=a9aa9d90c9227f17193f72ea945b42141ec2fd42;hb=c7a5ff20294ae8270bfb9120b8887f0c9959d658;hp=297649e623deb03cdd26d518dad8e5788fe2fc3c;hpb=f34fba2433c87ccdf824df0dc8c34099054b1715;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_Tools.cpp b/src/SketchPlugin/SketchPlugin_Tools.cpp index 297649e62..a9aa9d90c 100644 --- a/src/SketchPlugin/SketchPlugin_Tools.cpp +++ b/src/SketchPlugin/SketchPlugin_Tools.cpp @@ -9,8 +9,9 @@ #include #include #include -#include #include +#include +#include namespace SketchPlugin_Tools { @@ -60,7 +61,7 @@ void clearExpressions(FeaturePtr theFeature) } } -std::shared_ptr getCoincidencePoint(FeaturePtr theStartCoin) +std::shared_ptr getCoincidencePoint(const FeaturePtr theStartCoin) { std::shared_ptr aPnt = SketcherPrs_Tools::getPoint(theStartCoin.get(), SketchPlugin_Constraint::ENTITY_A()); @@ -69,26 +70,29 @@ std::shared_ptr getCoincidencePoint(FeaturePtr theStartCoin) return aPnt; } -void findCoincidences(FeaturePtr theStartCoin, - std::string theAttr, +void findCoincidences(const FeaturePtr theStartCoin, + const std::string& theAttr, std::set& theList) { AttributeRefAttrPtr aPnt = theStartCoin->refattr(theAttr); - if (!aPnt) return; + if(!aPnt) { + return; + } FeaturePtr aObj = ModelAPI_Feature::feature(aPnt->object()); - if (theList.find(aObj) == theList.end()) { + if(theList.find(aObj) == theList.end()) { std::shared_ptr aOrig = getCoincidencePoint(theStartCoin); - if (aOrig.get() == NULL) + if(aOrig.get() == NULL) { return; + } theList.insert(aObj); const std::set& aRefsList = aObj->data()->refsToMe(); std::set::const_iterator aIt; - for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { + for(aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) { std::shared_ptr aAttr = (*aIt); FeaturePtr aConstrFeature = std::dynamic_pointer_cast(aAttr->owner()); - if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { + if(aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) { std::shared_ptr aPnt = getCoincidencePoint(aConstrFeature); - if (aPnt.get() && aOrig->isEqual(aPnt)) { + if(aPnt.get() && aOrig->isEqual(aPnt)) { findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_A(), theList); findCoincidences(aConstrFeature, SketchPlugin_ConstraintCoincidence::ENTITY_B(), theList); } @@ -97,4 +101,57 @@ void findCoincidences(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