#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Tools.h>
#include <ModelAPI_ResultBody.h>
-#include <ModelAPI_ResultCompSolid.h>
#include <Events_Loop.h>
#include <Events_InfoMessage.h>
#include <TDF_ListIteratorOfLabelList.hxx>
#include <TDF_LabelMap.hxx>
#include <TDF_DeltaOnAddition.hxx>
+#include <TDataStd_UAttribute.hxx>
#include <TNaming_Builder.hxx>
#include <TNaming_SameShapeIterator.hxx>
#include <TNaming_Iterator.hxx>
// general sub-labels
/// where the reference to the current feature label is located (or no attribute if null feature)
static const int TAG_CURRENT_FEATURE = 1; ///< reference to the current feature
-static const int TAG_CURRENT_TRANSACTION = 2; ///< integer, index of the transaction
+/// integer, index of the transaction + GUID for auto recomutation blocking
+static const int TAG_CURRENT_TRANSACTION = 2;
static const int TAG_SELECTION_FEATURE = 3; ///< integer, tag of the selection feature label
static const int TAG_NODES_STATE = 4; ///< array, tag of the Object Browser nodes states
///< naming structures constructions selected from other document
static const int TAG_EXTERNAL_CONSTRUCTIONS = 5;
Model_Document::Model_Document(const int theID, const std::string theKind)
- : myID(theID), myKind(theKind), myIsActive(false),
+ : myID(theID), myKind(theKind), myIsActive(false), myIsSetCurrentFeature(false),
myDoc(new TDocStd_Document("BinOcaf")) // binary OCAF format
{
#ifdef TINSPECTOR
Handle(Model_Application) anApp = Model_Application::getApplication();
if (isRoot()) {
#ifdef WIN32
- CreateDirectory(theDirName, NULL);
+ CreateDirectory((LPTSTR) theDirName, NULL);
#else
mkdir(theDirName, 0x1ff);
#endif
return myObjs->size(theGroupID, theAllowFolder);
}
+std::shared_ptr<ModelAPI_Object> Model_Document::parent(
+ const std::shared_ptr<ModelAPI_Object> theChild)
+{
+ if(myObjs == 0) // may be on close
+ return ObjectPtr();
+ return myObjs->parent(theChild);
+}
+
std::shared_ptr<ModelAPI_Feature> Model_Document::currentFeature(const bool theVisible)
{
if (!myObjs) // on close document feature destruction it may call this method
void Model_Document::setCurrentFeature(
std::shared_ptr<ModelAPI_Feature> theCurrent, const bool theVisible)
{
+ if (myIsSetCurrentFeature)
+ return;
+ myIsSetCurrentFeature = true;
// blocks the flush signals to avoid each objects visualization in the viewer
// they should not be shown once after all modifications are performed
Events_Loop* aLoop = Events_Loop::loop();
std::shared_ptr<Model_Data> aData = std::static_pointer_cast<Model_Data>(theCurrent->data());
if (!aData.get() || !aData->isValid()) {
aLoop->activateFlushes(isActive);
+ myIsSetCurrentFeature = false;
return;
}
TDF_Label aFeatureLabel = aData->label().Father();
}
}
}
+ myIsSetCurrentFeature = false;
// unblock the flush signals and up them after this
aLoop->activateFlushes(isActive);
}
if (theContext != myObjs->object(aLabIter->Father()))
continue;
}
+ // copy aSubName to avoid incorrect further processing after its suffix cutting
+ TCollection_ExtendedString aSubNameCopy(aSubName);
// searching sub-labels with this name
TDF_ChildIDIterator aNamesIter(*aLabIter, TDataStd_Name::GetID(), Standard_True);
for(; aNamesIter.More(); aNamesIter.Next()) {
Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(aNamesIter.Value());
- if (aName->Get() == aSubName)
+ if (aName->Get() == aSubNameCopy)
return aName->Label();
}
// If not found child label with the exact sub-name, then try to find compound with
// such sub-name without suffix.
- Standard_Integer aSuffixPos = aSubName.SearchFromEnd('_');
- if (aSuffixPos != -1 && aSuffixPos != aSubName.Length()) {
- TCollection_ExtendedString anIndexStr = aSubName.Split(aSuffixPos);
- aSubName.Remove(aSuffixPos);
+ Standard_Integer aSuffixPos = aSubNameCopy.SearchFromEnd('_');
+ if (aSuffixPos != -1 && aSuffixPos != aSubNameCopy.Length()) {
+ TCollection_ExtendedString anIndexStr = aSubNameCopy.Split(aSuffixPos);
+ aSubNameCopy.Remove(aSuffixPos);
aNamesIter.Initialize(*aLabIter, TDataStd_Name::GetID(), Standard_True);
for(; aNamesIter.More(); aNamesIter.Next()) {
Handle(TDataStd_Name) aName = Handle(TDataStd_Name)::DownCast(aNamesIter.Value());
- if (aName->Get() == aSubName) {
+ if (aName->Get() == aSubNameCopy) {
return aName->Label();
}
}
// check also "this" label
Handle(TDataStd_Name) aName;
if (aLabIter->FindAttribute(TDataStd_Name::GetID(), aName)) {
- if (aName->Get() == aSubName) {
+ if (aName->Get() == aSubNameCopy) {
return aName->Label();
}
}
}
}
+ // verify context's name is same as sub-component's and use context's label
+ if (aSubName.IsEqual(anObjName.c_str()))
+ return *(aFind->second.rbegin());
}
}
return TDF_Label(); // not found
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(
object(ModelAPI_Feature::group(), a));
if (aFeature.get() && aFeature->data()->isValid()) {
- const std::list<std::shared_ptr<ModelAPI_Result> >& aResList = aFeature->results();
- std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResList.begin();
- for(; aRes != aResList.end(); aRes++) {
+ std::list<ResultPtr> aResults;
+ ModelAPI_Tools::allResults(aFeature, aResults);
+ for (std::list<ResultPtr>::iterator aRes = aResults.begin();
+ aRes != aResults.end(); aRes++) {
ModelAPI_EventCreator::get()->sendUpdated(*aRes, aRedispEvent);
- // #issue 1048: sub-compsolids also
- ResultCompSolidPtr aCompRes = std::dynamic_pointer_cast<ModelAPI_ResultCompSolid>(*aRes);
- if (aCompRes.get()) {
- int aNumSubs = aCompRes->numberOfSubs();
- for(int a = 0; a < aNumSubs; a++) {
- ResultPtr aSub = aCompRes->subResult(a);
- if (aSub.get()) {
- ModelAPI_EventCreator::get()->sendUpdated(aSub, aRedispEvent);
- }
- }
- }
}
}
}
if (aShape.IsNull())
return FeaturePtr();
- // for comsolids and compounds all the naming is located in the main object, so, try to use
+ // for compsolids and compounds all the naming is located in the main object, so, try to use
// it first
- ResultCompSolidPtr aMain = ModelAPI_Tools::compSolidOwner(theResult);
+ ResultBodyPtr aMain = ModelAPI_Tools::bodyOwner(theResult);
+ while (aMain.get()) { // get the top-most main
+ ResultBodyPtr aNextMain = ModelAPI_Tools::bodyOwner(aMain);
+ if (aNextMain.get())
+ aMain = aNextMain;
+ else break;
+ }
if (aMain.get()) {
FeaturePtr aMainRes = producedByFeature(aMain, theShape);
if (aMainRes)
subDoc(*aSubIter)->setExecuteFeatures(theFlag);
}
}
+
+void Model_Document::appendTransactionToPrevious()
+{
+ Transaction anAppended = myTransactions.back();
+ myTransactions.pop_back();
+ if (!myTransactions.empty()) { // if it is empty, just forget the appended
+ myTransactions.back().myOCAFNum += anAppended.myOCAFNum;
+ }
+ // propagate the same action to sub-documents
+ const std::set<int> aSubs = subDocuments();
+ for (std::set<int>::iterator aSubIter = aSubs.begin(); aSubIter != aSubs.end(); aSubIter++) {
+ subDoc(*aSubIter)->appendTransactionToPrevious();
+ }
+}
+
+/// GUID for keeping information about the auto-recomputation state
+static const Standard_GUID kAutoRecomputationID("8493fb74-0674-4912-a100-1cf46c7cfab3");
+
+void Model_Document::setAutoRecomutationState(const bool theState)
+{
+ if (theState)
+ generalLabel().FindChild(TAG_CURRENT_TRANSACTION).ForgetAttribute(kAutoRecomputationID);
+ else
+ TDataStd_UAttribute::Set(
+ generalLabel().FindChild(TAG_CURRENT_TRANSACTION), kAutoRecomputationID);
+}
+
+bool Model_Document::autoRecomutationState() const
+{
+ return !generalLabel().FindChild(TAG_CURRENT_TRANSACTION).IsAttribute(kAutoRecomputationID);
+}