static string anEmpty;
return anEmpty;
}
+
+bool Model_Data::isEqual(const boost::shared_ptr<ModelAPI_Data> theData)
+{
+ boost::shared_ptr<Model_Data> aData = boost::dynamic_pointer_cast<Model_Data>(theData);
+ if (aData)
+ return myLab.IsEqual(aData->myLab) == Standard_True;
+ return false;
+}
+
+bool Model_Data::isValid()
+{
+ return !myLab.IsNull() && myLab.HasAttribute();
+}
/// Identifier by the id (not fast, iteration by map)
/// \param theAttr attribute already created in this data
MODEL_EXPORT virtual const std::string& id(const boost::shared_ptr<ModelAPI_Attribute> theAttr);
+ /// Returns true if data belongs to same features
+ MODEL_EXPORT virtual bool isEqual(const boost::shared_ptr<ModelAPI_Data> theData);
+ /// Returns true if it is correctly connected t othe data model
+ MODEL_EXPORT virtual bool isValid();
/// Initializes object by the attributes: must be called just after the object is created
/// for each attribute of the object
{
// check is it nested or not
if (myDoc->HasOpenCommand()) {
- myIsNested = true;
+ myNestedStart = myTransactionsAfterSave;
}
// new command for this
myDoc->NewCommand();
void Model_Document::finishOperation()
{
+ if (myNestedStart > myTransactionsAfterSave) // this nested transaction is owervritten
+ myNestedStart = 0;
// returns false if delta is empty and no transaction was made
myIsEmptyTr[myTransactionsAfterSave] = !myDoc->CommitCommand();
myTransactionsAfterSave++;
- myIsNested = false;
// finish for all subs
set<string>::iterator aSubIter = mySubs.begin();
for(; aSubIter != mySubs.end(); aSubIter++)
bool Model_Document::canUndo()
{
- if (myDoc->GetAvailableUndos() > 0)
+ if (myDoc->GetAvailableUndos() > 0 && myNestedStart != myTransactionsAfterSave)
return true;
// check other subs contains operation that can be undoed
set<string>::iterator aSubIter = mySubs.begin();
aData->setLabel(anObjLab);
boost::shared_ptr<ModelAPI_Document> aThis =
Model_Application::getApplication()->getDocument(myID);
- theFeature->setData(aData);
theFeature->setDoc(aThis);
+ theFeature->setData(aData);
setUniqueName(theFeature);
theFeature->initAttributes();
// keep the feature ID to restore document later correctly
{
myDoc->SetUndoLimit(UNDO_LIMIT);
myTransactionsAfterSave = 0;
- myIsNested = false;
+ myNestedStart = 0;
myDoc->SetNestedTransactionMode();
// to have something in the document and avoid empty doc open/save problem
TDataStd_Integer::Set(myDoc->Main().Father(), 0);
TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(
aFLabIter.Value())->Get()).ToCString());
+ if (aFIter == aFeatures.end()) { // must be before "setData" to redo the sketch line correctly
+ aFeatures.push_back(aFeature);
+ aFIter = aFeatures.end();
+ } else {
+ aFIter++;
+ aFeatures.insert(aFIter, aFeature);
+ }
boost::shared_ptr<Model_Data> aData(new Model_Data);
TDF_Label aLab = aFLabIter.Value()->Label();
aData->setLabel(aLab);
aFeature->setData(aData);
aFeature->initAttributes();
- if (aFIter == aFeatures.end()) {
- aFeatures.push_back(aFeature);
- aFIter = aFeatures.end();
- } else {
- aFIter++;
- aFeatures.insert(aFIter, aFeature);
- }
// event: model is updated
static Events_ID anEvent = Events_Loop::eventByName(EVENT_FEATURE_CREATED);
Model_FeatureUpdatedMessage aMsg(aFeature, anEvent);
Handle_TDocStd_Document myDoc; ///< OCAF document
/// number of transactions after the last "save" call, used for "IsModified" method
int myTransactionsAfterSave;
+ /// number of myTransactionsAfterSave for the nested transaction start
+ int myNestedStart;
/// root labels of the features groups identified by names
std::map<std::string, TDF_Label> myGroups;
std::vector<std::string> myGroupsNames; ///< names of added groups to the document
std::set<std::string> mySubs; ///< set of identifiers of sub-documents of this document
/// transaction indexes (related to myTransactionsAfterSave) which were empty in this doc
std::map<int, bool> myIsEmptyTr;
- /// true if the current operation is nested
- bool myIsNested;
};
#endif
/// Identifier by the id (not fast, iteration by map)
/// \param theAttr attribute already created in this data
virtual const std::string& id(const boost::shared_ptr<ModelAPI_Attribute> theAttr) = 0;
+ /// Returns true if data belongs to same features
+ virtual bool isEqual(const boost::shared_ptr<ModelAPI_Data> theData) = 0;
+ /// Returns true if it is correctly connected t othe data model
+ virtual bool isValid() = 0;
/// Initializes object by the attributes: must be called just after the object is created
/// for each attribute of the object
{}
/// Sets the data manager of an object (document does)
- MODELAPI_EXPORT void setData(boost::shared_ptr<ModelAPI_Data> theData) {myData = theData;}
+ MODELAPI_EXPORT virtual void setData(boost::shared_ptr<ModelAPI_Data> theData)
+ {myData = theData;}
/// Sets the data manager of an object (document does)
MODELAPI_EXPORT void setDoc(boost::shared_ptr<ModelAPI_Document> theDoc) {myDoc = theDoc;}
#include "SketchPlugin_Feature.h"
+#include "SketchPlugin_Sketch.h"
+#include <ModelAPI_Document.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeRefList.h>
+
+SketchPlugin_Feature::SketchPlugin_Feature()
+{
+ mySketch = 0;
+}
+
+void SketchPlugin_Feature::setData(boost::shared_ptr<ModelAPI_Data> theData)
+{
+ ModelAPI_Feature::setData(theData);
+
+ // find sketch that references to this feature
+ int aSketches = document()->size("Construction");
+ for(int a = 0; a < aSketches && !mySketch; a++) {
+ boost::shared_ptr<SketchPlugin_Sketch> aSketch =
+ boost::dynamic_pointer_cast<SketchPlugin_Sketch>(document()->feature("Construction", a));
+ std::list<boost::shared_ptr<ModelAPI_Feature> > aList =
+ aSketch->data()->reflist(SKETCH_ATTR_FEATURES)->list();
+ std::list<boost::shared_ptr<ModelAPI_Feature> >::iterator aSub = aList.begin();
+ for(; aSub != aList.end(); aSub++) {
+ if ((*aSub)->data()->isEqual(theData)) {
+ mySketch = aSketch.get();
+ break;
+ }
+ }
+ }
+}
void SketchPlugin_Feature::setPreview(const boost::shared_ptr<GeomAPI_Shape>& theShape)
{
void setSketch(SketchPlugin_Sketch* theSketch) {mySketch = theSketch;}
/// Returns the sketch of this feature
SketchPlugin_Sketch* sketch() {return mySketch;}
+ /// initializes mySketch
+ SketchPlugin_Feature();
+ /// Sets the data manager of an object and here initializes mySketch field
+ SKETCHPLUGIN_EXPORT virtual void setData(boost::shared_ptr<ModelAPI_Data> theData);
friend class SketchPlugin_Sketch;
const double PLANE_SIZE = 200;
SketchPlugin_Line::SketchPlugin_Line()
+ : SketchPlugin_Feature()
{
setSketch(0);
}
objectBrowser()->setCurrentIndex(QModelIndex());
boost::shared_ptr<ModelAPI_PluginManager> aMgr = ModelAPI_PluginManager::get();
boost::shared_ptr<ModelAPI_Document> aDoc = aMgr->rootDocument();
- if (!operationMgr()->abortOperation())
- return;
+ //if (!operationMgr()->abortOperation())
+ // return;
+ operationMgr()->abortOperation();
aDoc->undo();
updateCommandStatus();
}