It must also be possible to enter the full angle value of the multi-rotation, with a toggle button defining the semantic of the angle value (either full rotation or between two consecutive repetitions).
For consistency, it should be the same for multi-translation.
<file>icons/angle_up_32x32.png</file>
<file>icons/angle_up_down.png</file>
<file>icons/angle_up_down_32x32.png</file>
+ <file>icons/angle_up_full_32x32.png</file>
<file>icons/dimension_up_down.png</file>
<file>icons/dimension_up_down_32x32.png</file>
<file>icons/by_two_points_32x32.png</file>
// Author: Artem ZHIDKOV
#include "SketchPlugin_MultiRotation.h"
+#include "SketchPlugin_Tools.h"
#include <GeomDataAPI_Point2D.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeString.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
#define PI 3.1415926535897932
SketchPlugin_MultiRotation::SketchPlugin_MultiRotation()
+: myBlockAngle(true)
{
}
void SketchPlugin_MultiRotation::initAttributes()
{
data()->addAttribute(CENTER_ID(), GeomDataAPI_Point2D::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());
attribute(CENTER_ID()));
if (!aCenter || !aCenter->isInitialized())
return;
+
+ if (attribute(ANGLE_ID())->isInitialized() && !attribute(ANGLE_FULL_ID())->isInitialized()) {
+ myBlockAngle = true;
+ SketchPlugin_Tools::updateAngleAttribute(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<ModelAPI_AttributeDouble>(
- attribute(ANGLE_ID()))->value();
+ attribute(ANGLE_ID()))->value();
+
// Convert angle to radians
anAngle *= PI / 180.0;
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::updateAngleAttribute(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::updateAngleAttribute(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()) {
+ 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::updateAngleAttribute(attribute(ANGLE_ID()), attribute(ANGLE_FULL_ID()),
+ aNbCopies, true);
+ else
+ SketchPlugin_Tools::updateAngleAttribute(attribute(ANGLE_FULL_ID()), attribute(ANGLE_ID()),
+ aNbCopies, false);
+
+ myBlockAngle = false;
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+ }
+ }
}
static const std::string MY_CENTER_ID("MultiRotationCenter");
return MY_CENTER_ID;
}
+ /// attribute name for first point
+ inline static const std::string& ANGLE_TYPE()
+ {
+ static const std::string ANGLE_TYPE_ATTR("AngleType");
+ return ANGLE_TYPE_ATTR;
+ }
+
/// End point of translation
inline static const std::string& ANGLE_ID()
{
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()
{
ObjectPtr copyFeature(ObjectPtr theObject);
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
}
}
+void updateAngleAttribute(const AttributePtr& theFirstAngleAttribute,
+ const AttributePtr& theSecondAngleAttribute,
+ const int& theNumberOfCopies,
+ const bool toFullAngle)
+{
+ if (theNumberOfCopies == 0)
+ return;
+
+ AttributeDoublePtr aDoubleFirstAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+ theFirstAngleAttribute);
+ double aValue = aDoubleFirstAttr->value();
+
+ AttributeDoublePtr aDoubleSecondAttr = std::dynamic_pointer_cast<ModelAPI_AttributeDouble>(
+ theSecondAngleAttribute);
+ if (toFullAngle)
+ aDoubleSecondAttr->setValue(aValue*theNumberOfCopies);
+ else
+ aDoubleSecondAttr->setValue(aValue/theNumberOfCopies);
+}
+
} // namespace SketchPlugin_Tools
#include <GeomAPI_Pnt2d.h>
#include <ModelAPI_Feature.h>
+#include <ModelAPI_Attribute.h>
namespace SketchPlugin_Tools {
const std::string& theAttr,
std::set<FeaturePtr>& theList);
+/// Changes the second attribute value to full or single angle. If it is corrected to full
+/// value, the first angle is miltipied to the number of copies otherwise it is separated by it.
+/// \param theFirstAngleAttribute the source attribute
+/// \param theSecondAngleAttribute the changed attribute
+/// \param theNumberOfCopies a value for modification
+/// \param toFullAngle a type of modification
+void updateAngleAttribute(const AttributePtr& theFirstAngleAttribute,
+ const AttributePtr& theSecondAngleAttribute,
+ const int& theNumberOfCopies,
+ const bool toFullAngle);
+
}; // namespace SketchPlugin_Tools
#endif // SKETCHPLUGIN_TOOLS_H_
\ No newline at end of file
title="Center of rotation"
tooltip="Center of rotation"
default="0"/>
- <point2dangle id="MultiRotationAngle"
+ <toolbox id="AngleType">
+ <box id="SingleAngle" title="Single angle" icon=":icons/angle_up_32x32.png">
+ <point2dangle id="MultiRotationAngle"
first_point="MultiRotationCenter"
label="Angle"
icon=":icons/angle.png"
tooltip="Rotation angle"
default="90"/>
+ </box>
+ <box id="FullAngle" title="Full angle" icon=":icons/angle_up_full_32x32.png">
+ <point2dangle id="MultiRotationFullAngle"
+ first_point="MultiRotationCenter"
+ label="Full angle"
+ icon=":icons/angle.png"
+ tooltip="Rotation angle"/>
+ </box>
+ </toolbox>
<integervalue id="MultiRotationObjects"
label="Total number of objects"
tooltip="Total number of objects"