#define UnLoadLib( handle ) dlclose( handle );
#endif
-class EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeature : public ModelAPI_Feature
+class ExchangePlugin_ImportFeature : public ModelAPI_Feature
{
public:
/// Extrusion kind
return MY_FILE_PATH_ID;
}
- ExchangePlugin_ImportFeature();
- virtual ~ExchangePlugin_ImportFeature();
+ EXCHANGEPLUGIN_EXPORT ExchangePlugin_ImportFeature();
+ EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ImportFeature();
/// Returns the unique kind of a feature
- virtual const std::string& getKind();
+ EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind();
/// Request for initialization of data model of the feature: adding all attributes
- virtual void initAttributes();
+ EXCHANGEPLUGIN_EXPORT virtual void initAttributes();
/// Computes or recomputes the results
- virtual void execute();
+ EXCHANGEPLUGIN_EXPORT virtual void execute();
- virtual bool isInHistory()
+ EXCHANGEPLUGIN_EXPORT virtual bool isInHistory()
{
return false;
}
protected:
- bool importFile(const std::string& theFileName);
- LibHandle loadImportPlugin(const std::string& theFormatName);
+ EXCHANGEPLUGIN_EXPORT bool importFile(const std::string& theFileName);
+ EXCHANGEPLUGIN_EXPORT LibHandle loadImportPlugin(const std::string& theFormatName);
};
ModelAPI_EventCreator::get()->sendUpdated(myObject, anEvent);
}
}
+
+void Model_Data::erase()
+{
+ if (!myLab.IsNull())
+ myLab.ForgetAllAttributes();
+}
{
myObject = theObject;
}
+
+ MODEL_EXPORT virtual void erase();
};
#endif
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeRefList.h>
#include <ModelAPI_Result.h>
+#include <ModelAPI_Validator.h>
#include <Events_Loop.h>
#include <Events_LongOp.h>
if (aMustbeUpdated) {
if (boost::dynamic_pointer_cast<Model_Document>(theFeature->document())->executeFeatures() ||
- !theFeature->isPersistentResult())
- theFeature->execute();
+ !theFeature->isPersistentResult()) {
+ ModelAPI_ValidatorsFactory* aFactory = ModelAPI_PluginManager::get()->validators();
+ if (aFactory->validate(theFeature)) {
+ theFeature->execute();
+ } else {
+ theFeature->eraseResults();
+ }
+ }
// redisplay all results
static Events_ID EVENT_DISP = Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY);
const std::list<boost::shared_ptr<ModelAPI_Result> >& aResults = theFeature->results();
/// makes attribute initialized
virtual void sendAttributeUpdated(ModelAPI_Attribute* theAttr) = 0;
+ /// Erases all the data from the data model
+ virtual void erase() = 0;
+
/// To virtually destroy the fields of successors
virtual ~ModelAPI_Data()
{
#include "ModelAPI_Feature.h"
#include <ModelAPI_Events.h>
#include <ModelAPI_Result.h>
+#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <Events_Loop.h>
std::list<boost::shared_ptr<ModelAPI_Result> >::iterator aResIter = myResults.begin();
for(; aResIter != myResults.end(); aResIter++) {
if (*aResIter == theResult) {
+ std::string aGroup = (*aResIter)->groupName();
+ (*aResIter)->data()->erase();
myResults.erase(aResIter);
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
+ ModelAPI_EventCreator::get()->sendDeleted(document(), aGroup);
+ break;
}
}
}
+void ModelAPI_Feature::eraseResults()
+{
+ std::list<boost::shared_ptr<ModelAPI_Result> >::iterator aResIter = myResults.begin();
+ for(; aResIter != myResults.end(); aResIter++) {
+ (*aResIter)->data()->erase();
+ static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
+ ModelAPI_EventCreator::get()->sendDeleted(document(), (*aResIter)->groupName());
+ }
+ myResults.clear();
+}
+
boost::shared_ptr<ModelAPI_Document> ModelAPI_Feature::documentToAdd()
{
return ModelAPI_PluginManager::get()->currentDocument();
const int theIndex);
/// removes the result from the feature
MODELAPI_EXPORT void removeResult(const boost::shared_ptr<ModelAPI_Result>& theResult);
+ /// removes all results from the feature
+ MODELAPI_EXPORT void eraseResults();
/// Returns true if result is persistent (stored in document) and on undo-redo, save-open
/// it is not needed to recompute it.
ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
aFactory->registerValidator("SketchPlugin_DistanceAttrValidator",
new SketchPlugin_DistanceAttrValidator);
+ aFactory->registerValidator("SketchPlugin_RadiusValidator",
+ new SketchPlugin_RadiusValidator);
aFactory->registerValidator("SketchPlugin_ResultPointValidator", new SketchPlugin_ResultPointValidator);
aFactory->registerValidator("SketchPlugin_ResultLineValidator", new SketchPlugin_ResultLineValidator);
aFactory->registerValidator("SketchPlugin_ResultArcValidator", new SketchPlugin_ResultArcValidator);
#include <ModelAPI_Data.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_ResultValidator.h>
+#include <ModelAPI_AttributeDouble.h>
#include <GeomDataAPI_Point2D.h>
bool SketchPlugin_DistanceAttrValidator::isValid(const FeaturePtr& theFeature,
}
return true; // it may be not reference attribute, in this case, it is OK
}
+
+bool SketchPlugin_RadiusValidator::isValid(
+ const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const
+{
+ boost::shared_ptr<ModelAPI_AttributeDouble> aDouble =
+ boost::dynamic_pointer_cast<ModelAPI_AttributeDouble>(theAttribute);
+ return aDouble->isInitialized() && aDouble->value() > 1.e-5;
+}
#include "SketchPlugin.h"
#include <ModelAPI_RefAttrValidator.h>
-class SketchPlugin_DistanceAttrValidator : public ModelAPI_AttributeValidator
+class SketchPlugin_DistanceAttrValidator : public ModelAPI_RefAttrValidator
{
public:
//! returns true if attribute is valid
};
+/**
+ * It must be bigger than 1.e-5
+ */
+class SketchPlugin_RadiusValidator : public ModelAPI_AttributeValidator
+{
+ public:
+ //! returns true if attribute is valid
+ //! \param theAttribute the checked attribute
+ //! \param theArguments arguments of the attribute
+ virtual bool isValid(
+ const AttributePtr& theAttribute, const std::list<std::string>& theArguments) const;
+
+};
+
#endif
</feature>
<feature id="SketchCircle" title="Circle" tooltip="Create a new circle" icon=":icons/circle.png">
<point_selector id="CircleCenter" title="Center" tooltip="Center of the circle"/>
- <point2ddistance id="CircleRadius" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set Radius"/>
+ <point2ddistance id="CircleRadius" first_point="CircleCenter" label="Radius:" min="0" step="1.0" default="0" icon=":icons/radius.png" tooltip="Set Radius">
+ <validator id="SketchPlugin_RadiusValidator"/>
+ </point2ddistance>
</feature>
<feature id="SketchArc" title="Arc" tooltip="Create a new arc of a circle" icon=":icons/arc.png">
<point_selector id="ArcCenter" title="Center" tooltip="Center of the arc"/>