#include <GeomDataAPI_Point2D.h>
+#include <ModelAPI_AttributeRefAttr.h>
void GeomDataAPI_Point2D::move(const double theDeltaX, const double theDeltaY)
{
return typeId();
}
+std::shared_ptr<GeomDataAPI_Point2D> GeomDataAPI_Point2D::getPoint2D(
+ const DataPtr& theData, const std::string& theAttribute)
+{
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr;
+ if (!theData)
+ return aPointAttr;
+
+ std::shared_ptr<ModelAPI_AttributeRefAttr> anAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeRefAttr>(theData->attribute(theAttribute));
+ if (anAttr && anAttr->attr()) {
+ aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr->attr());
+ }
+ return aPointAttr;
+}
+
+
GeomDataAPI_Point2D::GeomDataAPI_Point2D()
{
}
#include <GeomDataAPI.h>
#include <ModelAPI_Attribute.h>
+#include <ModelAPI_Data.h>
#include <set>
/// Returns the type of this class of attributes, not static method
GEOMDATAAPI_EXPORT virtual std::string attributeType();
+ /// Returns this attribute from the data if it is possible
+ /// \param theData a model data
+ /// \param theAttribute an attribute index
+ static GEOMDATAAPI_EXPORT std::shared_ptr<GeomDataAPI_Point2D> getPoint2D(const DataPtr& theData,
+ const std::string& theAttribute);
+
protected:
/// Objects are created for features automatically
GEOMDATAAPI_EXPORT GeomDataAPI_Point2D();
#include <ModelAPI_Data.h>
#include <ModelAPI_ResultConstruction.h>
#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_Events.h>
#include <ModelAPI_Session.h>
#include <SketcherPrs_Factory.h>
SketchPlugin_MultiTranslation::SketchPlugin_MultiTranslation()
-: myBlockValue(false)
{
}
{
data()->addAttribute(VALUE_TYPE(), ModelAPI_AttributeString::typeId());
- data()->addAttribute(START_POINT_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(START_FULL_POINT_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(END_POINT_ID(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(END_FULL_POINT_ID(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(START_POINT_ID(), ModelAPI_AttributeRefAttr::typeId());
+ data()->addAttribute(END_POINT_ID(), ModelAPI_AttributeRefAttr::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());
return;
// Calculate shift vector
- std::shared_ptr<GeomDataAPI_Point2D> aStart = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- attribute(START_POINT_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- attribute(END_POINT_ID()));
- 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;
- }
-
+ AttributeRefAttrPtr aStartAttr = data()->refattr(START_POINT_ID());
+ AttributeRefAttrPtr anEndAttr = data()->refattr(END_POINT_ID());
- // make a visible points
- SketchPlugin_Sketch::createPoint2DResult(this, sketch(), START_POINT_ID(), 0);
+ if (!aStartAttr || !anEndAttr || !aStartAttr->isInitialized() || !anEndAttr->isInitialized())
+ return;
- 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);
+ DataPtr aData = data();
+ std::shared_ptr<GeomDataAPI_Point2D> aStart = GeomDataAPI_Point2D::getPoint2D(aData,
+ START_POINT_ID());
+ std::shared_ptr<GeomDataAPI_Point2D> aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
+ END_POINT_ID());
+ if (!aStart || !aEnd)
+ return;
std::shared_ptr<GeomAPI_XY> aShiftVec(new GeomAPI_XY(aEnd->x() - aStart->x(), aEnd->y() - aStart->y()));
if (isUpdateFlushed)
Events_Loop::loop()->setFlushed(anUpdateEvent, false);
- std::shared_ptr<ModelAPI_Data> aData = data();
AttributeRefListPtr aRefListOfShapes = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear();
}
}
- else if (theID == START_POINT_ID() && !myBlockValue) {
- myBlockValue = true;
- std::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aStartFullPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_FULL_POINT_ID()));
- aStartFullPoint->setValue(aStartPoint->pnt());
- myBlockValue = false;
- }
- else if (theID == START_FULL_POINT_ID() && !myBlockValue) {
- myBlockValue = true;
- std::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_POINT_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aStartFullPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(START_FULL_POINT_ID()));
- aStartPoint->setValue(aStartFullPoint->pnt());
- myBlockValue = false;
- }
- 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));
- }
- }
- }
}
static const std::string MY_START_POINT_ID("MultiTranslationStartPoint");
return MY_START_POINT_ID;
}
- /// Start point of translation
- inline static const std::string& START_FULL_POINT_ID()
- {
- static const std::string MY_START_FULL_POINT_ID("MultiTranslationFullStartPoint");
- return MY_START_FULL_POINT_ID;
- }
/// End point of translation
inline static const std::string& END_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
<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"/>
+ <sketch_shape_selector
+ id="MultiTranslationStartPoint"
+ label="Start point"
+ tooltip="Start point of translation"
+ shape_types="vertex">
+ <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
+ <validator id="PartSet_DifferentObjects"/>
+ <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+ </sketch_shape_selector>
+ <sketch_shape_selector
+ id="MultiTranslationEndPoint"
+ label="End point"
+ tooltip="Final point of translation"
+ shape_types="vertex">
+ <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
+ <validator id="PartSet_DifferentObjects"/>
+ <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+ </sketch_shape_selector>
</groupbox>
</box>
<box id="FullValue" title="Full value" icon=":icons/translate_full_32x32.png">
<groupbox title="Direction">
- <sketch-2dpoint_selector
- id="MultiTranslationFullStartPoint"
- title="Start point"
- tooltip="Start point of translation"/>
- <sketch-2dpoint_selector
- id="MultiTranslationFullEndPoint"
- title="End point"
- tooltip="Final point of translation"/>
+ <sketch_shape_selector
+ id="MultiTranslationStartPoint"
+ label="Start point"
+ tooltip="Start point of translation"
+ shape_types="vertex">
+ <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
+ <validator id="PartSet_DifferentObjects"/>
+ <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+ </sketch_shape_selector>
+ <sketch_shape_selector
+ id="MultiTranslationEndPoint"
+ label="End point"
+ tooltip="Final point of translation"
+ shape_types="vertex">
+ <validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
+ <validator id="PartSet_DifferentObjects"/>
+ <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+ </sketch_shape_selector>
</groupbox>
</box>
</toolbox>
<integervalue id="MultiTranslationObjects"
label="Total number of objects"
- tooltip="Total number of objects"
+ tooltip="Total number of objects"
default="2" min="2" use_reset="false">
<validator id="GeomValidators_Positive"/>
</integervalue>
</feature>
-
+
<!-- SketchMultiRotation -->
<feature
id="SketchMultiRotation"
Events
ModelAPI
GeomAPI
+ GeomDataAPI
)
INCLUDE_DIRECTORIES(
#include <SketchPlugin_MultiTranslation.h>
+#include <ModelAPI_AttributeString.h>
+
+#include <GeomDataAPI_Point2D.h>
void SketchSolver_ConstraintMultiTranslation::getAttributes(
EntityWrapperPtr& theStartPoint, EntityWrapperPtr& theEndPoint,
{
return SketchPlugin_MultiTranslation::NUMBER_OF_OBJECTS_ID();
}
+
+void SketchSolver_ConstraintMultiTranslation::updateLocal()
+{
+ DataPtr aData = myBaseConstraint->data();
+ AttributePoint2DPtr aStartPointAttribute = GeomDataAPI_Point2D::getPoint2D(aData,
+ SketchPlugin_MultiTranslation::START_POINT_ID());
+ AttributePoint2DPtr anEndPointAttribute = GeomDataAPI_Point2D::getPoint2D(aData,
+ SketchPlugin_MultiTranslation::END_POINT_ID());
+ AttributeStringPtr aMethodTypeAttr = aData->string(SketchPlugin_MultiTranslation::VALUE_TYPE());
+ bool aFullValue = aMethodTypeAttr->value() != "SingleValue";
+
+ bool aStartPointChanged = aStartPointAttribute != myStartPointAttribute;
+ bool anEndPointChanged = anEndPointAttribute != myEndPointAttribute;
+ bool isMethodChanged = aFullValue != myIsFullValue;
+
+ if (aStartPointChanged)
+ myStartPointAttribute = aStartPointAttribute;
+ if (aStartPointChanged)
+ myEndPointAttribute = anEndPointAttribute;
+ if (isMethodChanged)
+ myIsFullValue = aFullValue;
+
+ if (aStartPointChanged || anEndPointChanged || isMethodChanged) {
+ DataPtr aData = myBaseConstraint->data();
+ std::list<ConstraintWrapperPtr> aConstraints = myStorage->constraint(myBaseConstraint);
+ std::list<ConstraintWrapperPtr>::const_iterator anIt = aConstraints.begin(),
+ aLast = aConstraints.end();
+ std::list<EntityWrapperPtr> anEntities;
+ for (; anIt != aLast; anIt++) {
+ ConstraintWrapperPtr aConstraint = *anIt;
+ aConstraint->setIsFullValue(myIsFullValue);
+ anEntities.clear();
+
+ const std::list<EntityWrapperPtr>& aConstraintEntities = aConstraint->entities();
+ std::list<EntityWrapperPtr>::const_iterator aSIt = aConstraintEntities.begin(),
+ aSLast = aConstraintEntities.end();
+ EntityWrapperPtr aStartEntity = *aSIt++;
+ if (aStartPointChanged) {
+ AttributePtr aStartPointAttr = aData->attribute(SketchPlugin_MultiTranslation::START_POINT_ID());
+ myStorage->update(aStartPointAttr);
+ aStartEntity = myStorage->entity(aStartPointAttr);
+ }
+ anEntities.push_back(aStartEntity);
+
+ EntityWrapperPtr anEndEntity = *aSIt++;
+ if (anEndPointChanged) {
+ AttributePtr anEndPointAttr = aData->attribute(SketchPlugin_MultiTranslation::END_POINT_ID());
+ myStorage->update(anEndPointAttr);
+ anEndEntity = myStorage->entity(anEndPointAttr);
+ }
+ anEntities.push_back(anEndEntity);
+
+ for (; aSIt != aSLast; ++aSIt)
+ anEntities.push_back(*aSIt);
+
+ aConstraint->setEntities(anEntities);
+ }
+ myStorage->addConstraint(myBaseConstraint, aConstraints);
+
+ myAdjusted = false;
+ }
+}
+
#include "SketchSolver.h"
#include <SketchSolver_ConstraintMulti.h>
+#include "GeomDataAPI_Point2D.h"
+
/** \class SketchSolver_ConstraintMultiTranslation
* \ingroup Plugins
* \brief Convert translated features to the list of SolveSpace constraints
std::list< std::list<EntityWrapperPtr> >& theEntities);
/// \brief Update parameters (called from base class)
- virtual void updateLocal()
- {}
+ virtual void updateLocal();
private:
/// \brief Returns name of NUMBER_OF_COPIES parameter for corresponding feature
virtual const std::string& nameNbObjects();
+
+private:
+ AttributePoint2DPtr myStartPointAttribute;
+ AttributePoint2DPtr myEndPointAttribute;
+ bool myIsFullValue;
};
#endif
const double& value() const
{ return myValue; }
+ /// \brief Store a boolean flag for full value using
+ void setIsFullValue(const bool& theFullValue)
+ { myIsFullValue = theFullValue; }
+ /// \brief Return a flag of a full value using
+ const bool& isFullValue() const
+ { return myIsFullValue; }
+
/// \brief Verify the feature is used in the constraint
virtual bool isUsed(FeaturePtr theFeature) const = 0;
/// \brief Verify the attribute is used in the constraint
ConstraintPtr myBaseConstraint;
std::list<EntityWrapperPtr> myConstrained;
double myValue;
+ bool myIsFullValue;
};
typedef std::shared_ptr<SketchSolver_IConstraintWrapper> ConstraintWrapperPtr;
std::shared_ptr<GeomAPI_Pnt2d> aEndPnt = aBuilder->point(*aSIt++);
std::shared_ptr<GeomAPI_XY> aDelta = aEndPnt->xy()->decreased(aStartPnt->xy());
+ bool isFullValue = theConstraint->isFullValue();
+ int aNbObjects = aSubs.size()-3;
+ if (isFullValue && aNbObjects > 0) {
+ aDelta->setX(aDelta->x()/aNbObjects);
+ aDelta->setY(aDelta->y()/aNbObjects);
+ }
+
std::list<EntityWrapperPtr>::const_iterator aPrevIt = aSIt++;
for (; aSIt != aSubs.end(); ++aPrevIt, ++aSIt)
translate(*aPrevIt, *aSIt, aDelta);