double theX, double theY)
{
bool aPointIsFound = false;
+
+ if (feature()->getKind() != SketchPlugin_Line::ID())
+ return aPointIsFound;
+
AttributePtr aWidgetAttribute = myFeature->attribute(attributeID());
std::shared_ptr<GeomAPI_Pnt2d> aPnt2d =
<file>icons/coincedence.png</file>
<file>icons/mirror.png</file>
<file>icons/translate.png</file>
+ <file>icons/translate_32x32.png</file>
+ <file>icons/translate_full_32x32.png</file>
<file>icons/rotate.png</file>
<file>icons/exec_state_failed.png</file>
<file>icons/exec_state_invalid_parameters.png</file>
// Author: Artem ZHIDKOV
#include "SketchPlugin_MultiTranslation.h"
+#include "SketchPlugin_Tools.h"
#include <GeomAPI_XY.h>
#include <GeomDataAPI_Point2D.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_Validator.h>
#include <SketcherPrs_Factory.h>
SketchPlugin_MultiTranslation::SketchPlugin_MultiTranslation()
+: myBlockValue(false)
{
}
void SketchPlugin_MultiTranslation::initAttributes()
{
+ data()->addAttribute(VALUE_TYPE(), ModelAPI_AttributeString::typeId());
+
data()->addAttribute(START_POINT_ID(), GeomDataAPI_Point2D::typeId());
data()->addAttribute(END_POINT_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(END_FULL_POINT_ID(), GeomDataAPI_Point2D::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());
if (!aStart || !aEnd || !aStart->isInitialized() || !aEnd->isInitialized())
return;
+ if (attribute(END_POINT_ID())->isInitialized() && !attribute(END_FULL_POINT_ID())->isInitialized()) {
+ myBlockValue = true;
+ SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()),
+ attribute(END_FULL_POINT_ID()), aNbCopies, true);
+ myBlockValue = false;
+ }
+
+
// make a visible points
SketchPlugin_Sketch::createPoint2DResult(this, sketch(), START_POINT_ID(), 0);
- SketchPlugin_Sketch::createPoint2DResult(this, sketch(), END_POINT_ID(), 1);
+
+ std::string aSecondPointAttributeID = END_POINT_ID();
+ AttributeStringPtr aMethodTypeAttr = string(VALUE_TYPE());
+ std::string aMethodType = aMethodTypeAttr->value();
+ if (aMethodType != "SingleValue")
+ aSecondPointAttributeID = END_FULL_POINT_ID();
+ SketchPlugin_Sketch::createPoint2DResult(this, sketch(), aSecondPointAttributeID, 1);
std::shared_ptr<GeomAPI_XY> aShiftVec(new GeomAPI_XY(aEnd->x() - aStart->x(), aEnd->y() - aStart->y()));
data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear();
}
}
+ else if (theID == END_POINT_ID() && !myBlockValue) {
+ int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
+ if (aNbCopies > 0) {
+ myBlockValue = true;
+ SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()),
+ attribute(END_FULL_POINT_ID()), aNbCopies, true);
+ myBlockValue = false;
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ }
+ }
+ else if (theID == END_FULL_POINT_ID() && !myBlockValue) {
+ int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
+ if (aNbCopies > 0) {
+ myBlockValue = true;
+ SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_FULL_POINT_ID()),
+ attribute(END_POINT_ID()), aNbCopies, false);
+ myBlockValue = 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(END_POINT_ID())->isInitialized() &&
+ attribute(VALUE_TYPE())->isInitialized()) {
+ AttributeStringPtr aMethodTypeAttr = string(VALUE_TYPE());
+ std::string aMethodType = aMethodTypeAttr->value();
+ int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value() - 1;
+ if (aNbCopies > 0) {
+ myBlockValue = true;
+ if (aMethodType == "SingleValue")
+ SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_POINT_ID()),
+ attribute(END_FULL_POINT_ID()), aNbCopies, true);
+ else {
+ SketchPlugin_Tools::updateMultiAttribute(attribute(START_POINT_ID()), attribute(END_FULL_POINT_ID()),
+ attribute(END_POINT_ID()), aNbCopies, false);
+ }
+ myBlockValue = false;
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ }
+ }
+ }
}
return MY_TRANSLATION_LIST_ID;
}
+ /// attribute name for first point
+ inline static const std::string& VALUE_TYPE()
+ {
+ static const std::string VALUE_TYPE_ATTR("ValueType");
+ return VALUE_TYPE_ATTR;
+ }
+
/// Start point of translation
inline static const std::string& START_POINT_ID()
{
static const std::string MY_END_POINT_ID("MultiTranslationEndPoint");
return MY_END_POINT_ID;
}
+ /// End point of translation
+ inline static const std::string& END_FULL_POINT_ID()
+ {
+ static const std::string MY_END_FULL_POINT_ID("MultiTranslationFullEndPoint");
+ return MY_END_FULL_POINT_ID;
+ }
+
/// Total number of objects, initial and translated objects
inline static const std::string& NUMBER_OF_OBJECTS_ID()
{
private:
ObjectPtr copyFeature(ObjectPtr theObject);
+
+private:
+ bool myBlockValue; /// a boolean state to avoid recusive value change in attributeChanged
};
#endif
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<GeomDataAPI_Point2D> aFirstPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFirstAttribute);
+ std::shared_ptr<GeomDataAPI_Point2D> aSecondPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theSecondAttribute);
+ std::shared_ptr<GeomDataAPI_Point2D> aModifiedPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(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
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
use_external="true">
<validator id="SketchPlugin_CopyValidator" />
</sketch_multi_selector>
- <groupbox title="Direction">
- <sketch-2dpoint_selector
- id="MultiTranslationStartPoint"
- title="Start point"
- tooltip="Start point of translation"/>
- <sketch-2dpoint_selector
- id="MultiTranslationEndPoint"
- title="End point"
- tooltip="Final point of translation"/>
- </groupbox>
+ <toolbox id="ValueType">
+ <box id="SingleValue" title="Single value" icon=":icons/translate_32x32.png">
+ <groupbox title="Direction">
+ <sketch-2dpoint_selector
+ id="MultiTranslationStartPoint"
+ title="Start point"
+ tooltip="Start point of translation"/>
+ <sketch-2dpoint_selector
+ id="MultiTranslationEndPoint"
+ title="End point"
+ tooltip="Final point of translation"/>
+ </groupbox>
+ </box>
+ <box id="FullValue" title="Full value" icon=":icons/translate_full_32x32.png">
+ <groupbox title="Direction">
+ <sketch-2dpoint_selector
+ id="MultiTranslationStartPoint"
+ title="Start point"
+ tooltip="Start point of translation"/>
+ <sketch-2dpoint_selector
+ id="MultiTranslationFullEndPoint"
+ title="End point"
+ tooltip="Final point of translation"/>
+ </groupbox>
+ </box>
+ </toolbox>
<integervalue id="MultiTranslationObjects"
label="Total number of objects"
tooltip="Total number of objects"
#include <ModuleBase_PageBase.h>
#include <ModuleBase_PageWidget.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
+
#include <QEvent>
#include <QFrame>
#include <QIcon>
activateWidget(NULL);
return;
}
+ ModelAPI_ValidatorsFactory* aValidators = ModelAPI_Session::get()->validators();
+
QList<ModuleBase_ModelWidget*>::const_iterator anIt = myWidgets.begin(), aLast = myWidgets.end();
bool isFoundWidget = false;
activateWindow();
for (; anIt != aLast; anIt++) {
+ ModuleBase_ModelWidget* aCurrentWidget = *anIt;
if (isFoundWidget || !theWidget) {
- if ((*anIt)->focusTo()) {
+
+ if (!aValidators->isCase(aCurrentWidget->feature(), aCurrentWidget->attributeID()))
+ continue; // this attribute is not participated in the current case
+
+ if (aCurrentWidget->focusTo()) {
return;
}
}