bool isRoot = theDocID == "root"; // the document is root
std::shared_ptr<Model_Document> aNew(
new Model_Document(theDocID, isRoot ? thePartSetKind : thePartKind));
- aNew->setThis(aNew);
myDocs[theDocID] = aNew;
// load it if it must be loaded by demand
if (myLoadedByDemand.find(theDocID) != myLoadedByDemand.end() && !myPath.empty()) {
- aNew->load(myPath.c_str());
+ aNew->load(myPath.c_str(), aNew);
myLoadedByDemand.erase(theDocID); // done, don't do it anymore
} else {
+ aNew->setThis(aNew);
static Events_ID anId = ModelAPI_DocumentCreatedMessage::eventId();
std::shared_ptr<ModelAPI_DocumentCreatedMessage> aMessage = std::shared_ptr
<ModelAPI_DocumentCreatedMessage>(new ModelAPI_DocumentCreatedMessage(anId, this));
#include <TDF_AttributeIterator.hxx>
#include <TDF_ChildIterator.hxx>
#include <TDF_RelocationTable.hxx>
+#include <Standard_GUID.hxx>
+#include <TDataStd_UAttribute.hxx>
#include <string>
}
}
}
+
+const Standard_GUID kIsInHistory("9275e461-4aca-46c7-ad84-1efb569d8144");
+
+bool Model_Data::isInHistory()
+{
+ return !myLab.IsAttribute(kIsInHistory);
+}
+
+void Model_Data::setIsInHistory(const bool theFlag)
+{
+ if (theFlag) { // is in histiry true: default behavior, so, remove GUID
+ myLab.ForgetAttribute(kIsInHistory);
+ } else { // not standard behavior is defined by special GUID attribute
+ TDataStd_UAttribute::Set(myLab, kIsInHistory);
+ }
+}
/// Copies all atributes content into theTarget data
MODEL_EXPORT virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget);
+protected:
+ /// Returns true if "is in history" custom behaviors is defined for the feature
+ MODEL_EXPORT virtual bool isInHistory();
+
+ /// Defines the custom "is in history" behavior
+ MODEL_EXPORT virtual void setIsInHistory(const bool theFlag);
+
private:
/// Removes all information about back references
void eraseBackReferences();
return this == Model_Session::get()->moduleDocument().get();
}
-bool Model_Document::load(const char* theFileName)
+bool Model_Document::load(const char* theFileName, DocumentPtr theThis)
{
Handle(Model_Application) anApp = Model_Application::getApplication();
if (isRoot()) {
std::dynamic_pointer_cast<Model_Session>(Model_Session::get());
aSession->setActiveDocument(anApp->getDocument(myID), false);
aSession->setCheckTransactions(false);
- DocumentPtr aThis = myObjs->owner();
- delete myObjs;
+ if (myObjs)
+ delete myObjs;
myObjs = new Model_Objects(myDoc->Main()); // synchronisation is inside
- myObjs->setOwner(aThis);
+ myObjs->setOwner(theThis);
+ // update the current features status
+ setCurrentFeature(currentFeature(false), false);
aSession->setCheckTransactions(true);
aSession->setActiveDocument(Model_Session::get()->moduleDocument(), false);
aSession->setActiveDocument(anApp->getDocument(myID), true);
subDoc(*aSubIter)->undoInternal(theWithSubs, theSynchronize);
}
// after redo of all sub-documents to avoid updates on not-modified data (issue 370)
- if (theSynchronize)
+ if (theSynchronize) {
+ // update the current features status
+ setCurrentFeature(currentFeature(false), false);
myObjs->synchronizeFeatures(true, true, isRoot());
+ }
}
void Model_Document::undo()
for (; aSubIter != aSubs.end(); aSubIter++)
subDoc(*aSubIter)->redo();
+ // update the current features status
+ setCurrentFeature(currentFeature(false), false);
// after redo of all sub-documents to avoid updates on not-modified data (issue 370)
myObjs->synchronizeFeatures(true, true, isRoot());
}
const std::set<std::string> Model_Document::subDocuments(const bool theActivatedOnly) const
{
std::set<std::string> aResult;
- int aNum = myObjs->size(ModelAPI_ResultPart::group());
- for(int a = 0; a < aNum; a++) {
- ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(
- myObjs->object(ModelAPI_ResultPart::group(), a));
+ std::list<ResultPtr> aPartResults;
+ myObjs->allResults(ModelAPI_ResultPart::group(), aPartResults);
+ std::list<ResultPtr>::iterator aPartRes = aPartResults.begin();
+ for(; aPartRes != aPartResults.end(); aPartRes++) {
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aPartRes);
if (aPart && (!theActivatedOnly || aPart->isActivated()))
aResult.insert(aPart->data()->name());
}
//! Loads the OCAF document from the file.
//! \param theFileName full name of the file to load
+ //! \param theThis the common shared pointer to the document to manage with it later
//! \returns true if file was loaded successfully
- MODEL_EXPORT virtual bool load(const char* theFileName);
+ MODEL_EXPORT virtual bool load(const char* theFileName, DocumentPtr theThis);
//! Saves the OCAF document to the file.
//! \param theFileName full name of the file to store
Model_Objects::Model_Objects(TDF_Label theMainLab) : myMain(theMainLab)
{
+}
+
+void Model_Objects::setOwner(DocumentPtr theDoc)
+{
+ myDoc = theDoc;
// update all fields and recreate features and result objects if needed
synchronizeFeatures(false, true, true);
+ myHistory.clear();
}
Model_Objects::~Model_Objects()
return myHistory[theGroupID].size();
}
+void Model_Objects::allResults(const std::string& theGroupID, std::list<ResultPtr>& theResults)
+{
+ // iterate the array of references and get feature by feature from the array
+ Handle(TDataStd_ReferenceArray) aRefs;
+ if (featuresLabel().FindAttribute(TDataStd_ReferenceArray::GetID(), aRefs)) {
+ for(int a = aRefs->Lower(); a <= aRefs->Upper(); a++) {
+ FeaturePtr aFeature = feature(aRefs->Value(a));
+ if (aFeature.get()) {
+ const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = aFeature->results();
+ std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.begin();
+ for (; aRIter != aResults.cend(); aRIter++) {
+ ResultPtr aRes = *aRIter;
+ if (aRes->groupName() != theGroupID) break; // feature have only same group results
+ if (aRes->isInHistory() && !aRes->isConcealed()) {
+ theResults.push_back(*aRIter);
+ }
+ }
+ }
+ }
+ }
+}
+
+
TDF_Label Model_Objects::featuresLabel() const
{
return myMain.FindChild(TAG_OBJECTS);
aResIter++;
}
// it may be on undo
- if (!theFeature->data() || !theFeature->data()->isValid())
+ if (!theFeature->data() || !theFeature->data()->isValid() || theFeature->isDisabled())
return;
// check that results are presented on all labels
int aResSize = theFeature->results().size();
//! Returns the number of features in the group
int size(const std::string& theGroupID);
+ ///! Returns all (and disabled) results of the given type. Not fast method (iterates all features).
+ void allResults(const std::string& theGroupID, std::list<ResultPtr>& theResults);
+
/// Creates a construction cresults
std::shared_ptr<ModelAPI_ResultConstruction> createConstruction(
const std::shared_ptr<ModelAPI_Data>& theFeatureData, const int theIndex = 0);
feature(const std::shared_ptr<ModelAPI_Result>& theResult);
//! Sets the owner of this manager
- void setOwner(DocumentPtr theDoc) {myDoc = theDoc;}
+ void setOwner(DocumentPtr theDoc);
//! Returns the owner of this manager
DocumentPtr owner() {return myDoc;}
bool Model_Session::load(const char* theFileName)
{
- bool aRes = ROOT_DOC->load(theFileName);
+ bool aRes = ROOT_DOC->load(theFileName, ROOT_DOC);
return aRes;
}
/// Copies all atributes content into theTarget data
virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget) = 0;
-
protected:
/// Objects are created for features automatically
ModelAPI_Data();
+
+ /// Returns true if "is in history" custom behaviors is defined for the feature
+ virtual bool isInHistory() = 0;
+
+ /// Defines the custom "is in history" behavior
+ virtual void setIsInHistory(const bool theFlag) = 0;
+
+ friend class ModelAPI_Object;
};
typedef std::shared_ptr<ModelAPI_Data> DataPtr;
bool ModelAPI_Object::isInHistory()
{
- return myInHistory;
+ if (myData.get() && myData->isValid()) {
+ return myData->isInHistory();
+ }
+ return true; // default value
}
void ModelAPI_Object::setInHistory(
const std::shared_ptr<ModelAPI_Object> theObject, const bool theFlag)
{
- if (myInHistory != theFlag) {
- myInHistory = theFlag;
+ if (isInHistory() != theFlag) {
+ if (myData.get() && myData->isValid()) {
+ myData->setIsInHistory(theFlag);
+ }
myDoc->updateHistory(theObject);
}
}
{
}
-ModelAPI_Object::ModelAPI_Object() : myInHistory(true)
+ModelAPI_Object::ModelAPI_Object()
{
}
{
std::shared_ptr<ModelAPI_Data> myData; ///< manager of the data model of a feature
std::shared_ptr<ModelAPI_Document> myDoc; ///< document this object belongs to
- bool myInHistory; ///< keep the information about the presense of the object in the history tree
public:
/// By default object is displayed in the object browser.
MODELAPI_EXPORT virtual bool isInHistory();
if (!aPart.get()) {
aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aPartFeature->firstResult());
}
- aPartDoc = aPart->partDoc();
+ if (aPart.get()) // this may be null is Part feature is disabled
+ aPartDoc;
if (aMgr->activeDocument() == aPartDoc)
theMenu->addAction(myMenuMgr->action("DEACTIVATE_PART_CMD"));
else
ObjectPtr aObject = aRootDoc->object(ModelAPI_Feature::group(), myId);
FeaturePtr aFeature = ModelAPI_Feature::feature(aObject);
ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(aFeature->firstResult());
- return aPart->partDoc();
+ if (aPart.get()) // this may be null is Part feature is disabled
+ return aPart->partDoc();
+ return DocumentPtr();
}
ObjectPtr PartSet_PartDataModel::object(const QModelIndex& theIndex) const