int Model_Document::size(const std::string& theGroupID)
{
+ if (myObjs == 0) // may be on close
+ return 0;
return myObjs->size(theGroupID);
}
bool Model_ResultPart::isActivated()
{
if (myTrsf.get()) {
+ if (!baseRef().get()) // may be on close
+ return false;
return baseRef()->isActivated();
}
std::shared_ptr<ModelAPI_Document> aPrevious = myCurrentDoc;
myCurrentDoc = theDoc;
if (theDoc.get() && theSendSignal) {
+ // this must be before the synchronisation call because features in PartSet lower than this
+ // part feature must be disabled and don't recomputed anymore (issue 1156,
+ // translation feature is failed on activation of Part 2)
+ if (isOperation()) { // do it only in transaction, not on opening of document
+ DocumentPtr aRoot = moduleDocument();
+ if (myCurrentDoc != aRoot) {
+ FeaturePtr aPartFeat = ModelAPI_Tools::findPartFeature(aRoot, myCurrentDoc);
+ if (aPartFeat.get()) {
+ aRoot->setCurrentFeature(aPartFeat, false);
+ }
+ }
+ }
// syncronize the document: it may be just opened or opened but removed before
std::shared_ptr<Model_Document> aDoc = std::dynamic_pointer_cast<Model_Document>(theDoc);
if (aDoc.get()) {
} else {
// make the current feature the latest in sub, root current feature becomes this sub
makeCurrentLast(myCurrentDoc);
- DocumentPtr aRoot = moduleDocument();
- ResultPtr aPartRes = ModelAPI_Tools::findPartResult(aRoot, myCurrentDoc);
- if (aPartRes.get()) {
- FeaturePtr aPartFeat = aRoot->feature(aPartRes);
- if (aPartFeat.get()) {
- aRoot->setCurrentFeature(aPartFeat, false);
- }
- }
}
}
}
return ResultPtr();
}
+FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub)
+{
+ if (theMain != theSub) { // to optimize and avoid of crash on partset document close (don't touch the sub-document structure)
+ for (int a = theMain->size(ModelAPI_Feature::group()) - 1; a >= 0; a--) {
+ FeaturePtr aPartFeat = std::dynamic_pointer_cast<ModelAPI_Feature>(
+ theMain->object(ModelAPI_Feature::group(), a));
+ if (aPartFeat.get()) {
+ const std::list<std::shared_ptr<ModelAPI_Result> >& aResList = aPartFeat->results();
+ std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRes = aResList.begin();
+ for(; aRes != aResList.end(); aRes++) {
+ ResultPartPtr aPart = std::dynamic_pointer_cast<ModelAPI_ResultPart>(*aRes);
+ if (aPart.get()) {
+ if (aPart->isActivated() && aPart->partDoc() == theSub)
+ return aPartFeat;
+ } else break; // if the first is not Part, others are also not
+ }
+ }
+ }
+ }
+ return FeaturePtr();
+}
+
CompositeFeaturePtr compositeOwner(const FeaturePtr& theFeature)
{
if (theFeature.get() && theFeature->data()->isValid()) {
/*!
* Searches for Part result that contains the reference to the given document.
+ * The result must be presented in the tree.
* \param theMain document that contains the searched feature
* \param theSub document that is searched, the resulting feature references to it
* \returns null if not found
*/
MODELAPI_EXPORT ResultPtr findPartResult(const DocumentPtr& theMain, const DocumentPtr& theSub);
+/*!
+ * Searches for Part the feature that contains in result the reference to the given document.
+ * The result may be disabled.
+ * \param theMain document that contains the searched feature
+ * \param theSub document that is searched, the resulting feature references to it
+ * \returns null if not found
+ */
+MODELAPI_EXPORT FeaturePtr findPartFeature(const DocumentPtr& theMain, const DocumentPtr& theSub);
+
/*!
* Returns the composite feature - parent of this feature.
* \param theFeature the sub-element of composite