if (theObject.get() != NULL) {
aData = std::dynamic_pointer_cast<Model_Data>(theObject->data());
myRef->Remove(aData->label().Father());
+ REMOVE_BACK_REF(theObject);
}
else { // in case of empty object remove, the first empty object is removed from the list
std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(
myIsInitialized = myRef.isInitialized();
}
+void Model_AttributeSelection::setID(const std::string theID)
+{
+ myRef.setID(theID);
+ ModelAPI_AttributeSelection::setID(theID);
+}
+
ResultPtr Model_AttributeSelection::context() {
return std::dynamic_pointer_cast<ModelAPI_Result>(myRef.value());
}
/// Returns the prepared map of valid labels for naming selection solving (creates if not exists)
TDF_LabelMap& scope();
+ /// Sets the ID of the attribute in Data (called from Data): here it is used for myRef ID setting
+ MODELAPI_EXPORT virtual void setID(const std::string theID);
+
friend class Model_Data;
friend class Model_AttributeSelectionList;
};
if (owner()) {
aNewAttr->setObject(owner());
}
+ aNewAttr->setID(id());
mySize->Set(aNewTag);
aNewAttr->setValue(theContext, theSubShape);
owner()->data()->sendAttributeUpdated(this);
MODELAPI_EXPORT ModelAPI_Attribute();
/// Sets the ID of the attribute in Data (called from Data)
- MODELAPI_EXPORT void setID(const std::string theID);
+ MODELAPI_EXPORT virtual void setID(const std::string theID);
friend class Model_Data;
};
new SketchPlugin_NotFixedValidator);
aFactory->registerValidator("SketchPlugin_EqualAttr",
new SketchPlugin_EqualAttrValidator);
+ aFactory->registerValidator("SketchPlugin_MirrorAttr",
+ new SketchPlugin_MirrorAttrValidator);
// register this plugin
ModelAPI_Session::get()->registerPlugin(this);
#include <ModelAPI_Validator.h>
#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <ModelAPI_AttributeRefList.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Session.h>
#include <GeomValidators_Edge.h>
return true;
}
+bool SketchPlugin_MirrorAttrValidator::isValid(
+ const AttributePtr& theAttribute, const std::list<std::string>& theArguments ) const
+{
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ AttributeSelectionListPtr aSelAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+ if (!aSelAttr)
+ return false;
+
+ AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+ aFeature->attribute(SketchPlugin_Constraint::ENTITY_C()));
+ std::list<ObjectPtr> aMirroredObjects = aRefListOfMirrored->list();
+
+ for(int anInd = 0; anInd < aSelAttr->size(); anInd++) {
+ std::shared_ptr<ModelAPI_AttributeSelection> aSelect = aSelAttr->value(anInd);
+ std::list<ObjectPtr>::iterator aMirIter = aMirroredObjects.begin();
+ for (; aMirIter != aMirroredObjects.end(); aMirIter++)
+ if (aSelect->context() == *aMirIter)
+ return false;
+ }
+ return true;
+}
+
const std::list<std::string>& theArguments) const;
};
+/**\class SketchPlugin_MirrorAttrValidator
+ * \ingroup Validators
+ * \brief Validator for the mirror constraint input.
+ *
+ * It checks that attributes of the Mirror constraint are correct.
+ */
+class SketchPlugin_MirrorAttrValidator : public ModelAPI_AttributeValidator
+{
+ public:
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute (not used)
+ virtual bool isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const;
+};
+
#endif
label="List of objects"
tooltip="Select list of mirroring objects"
type_choice="Edges">
+ <validator id="SketchPlugin_MirrorAttr" />
</multi_selector>
</feature>
</group>
}
anExtraIt++;
}
- return isFullyRemoved;
+ return mySlvsConstraints.empty();
}
if (anEntIter->distance == theEntityID)
return false;
}
+ std::set<Slvs_hEntity> anEntAndSubs;
+ anEntAndSubs.insert(theEntityID);
+ for (int i = 0; i < 4; i++)
+ if (myEntities[aPos].point[i] != SLVS_E_UNKNOWN)
+ anEntAndSubs.insert(myEntities[aPos].point[i]);
+
std::vector<Slvs_Constraint>::const_iterator aConstrIter = myConstraints.begin();
for (; aConstrIter != myConstraints.end(); aConstrIter++) {
Slvs_hEntity anEntIDs[6] = {aConstrIter->ptA, aConstrIter->ptB,
aConstrIter->entityA, aConstrIter->entityB,
aConstrIter->entityC, aConstrIter->entityD};
for (int i = 0; i < 6; i++)
- if (anEntIDs[i] == theEntityID)
+ if (anEntAndSubs.find(anEntIDs[i]) != anEntAndSubs.end())
return false;
}
// The entity is not used, remove it and its parameters