-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "ModelAPI_Tools.h"
return theResult->shape();
}
+// LCOV_EXCL_START
const char* toString(ModelAPI_ExecState theExecState)
{
switch (theExecState) {
return anError;
}
+// LCOV_EXCL_STOP
ObjectPtr objectByName(const DocumentPtr& theDocument, const std::string& theGroup,
const std::string& theName)
return CompositeFeaturePtr(); // not found
}
-ResultBodyPtr bodyOwner(const ResultPtr& theSub)
+ResultBodyPtr bodyOwner(const ResultPtr& theSub, const bool theRoot)
{
if (theSub.get()) {
ObjectPtr aParent = theSub->document()->parent(theSub);
if (aParent.get()) {
+ if (theRoot) { // try to find parent of parent
+ ResultPtr aResultParent = std::dynamic_pointer_cast<ModelAPI_Result>(aParent);
+ ResultBodyPtr aGrandParent = bodyOwner(aResultParent, true);
+ if (aGrandParent.get())
+ aParent = aGrandParent;
+ }
return std::dynamic_pointer_cast<ModelAPI_ResultBody>(aParent);
}
}
}
}
-std::pair<std::string, bool> getDefaultName(const std::shared_ptr<ModelAPI_Result>& theResult)
+std::pair<std::string, bool> getDefaultName(const std::shared_ptr<ModelAPI_Result>& theResult,
+ const bool theInherited)
{
typedef std::list< std::pair < std::string, std::list<ObjectPtr> > > ListOfReferences;
DataPtr aData = anOwner->data();
ListOfReferences aReferences;
- aData->referencesToObjects(aReferences);
-
// find first result with user-defined name
ListOfReferences::const_iterator aFoundRef = aReferences.end();
- for (ListOfReferences::const_iterator aRefIt = aReferences.begin();
- aRefIt != aReferences.end(); ++aRefIt) {
- bool isConcealed = aSession->validators()->isConcealed(anOwner->getKind(), aRefIt->first);
- bool isMainArg = isConcealed &&
- aSession->validators()->isMainArgument(anOwner->getKind(), aRefIt->first);
- if (isConcealed) {
- // check the referred object is a Body
- // (for example, ExtrusionCut has a sketch as a first attribute which is concealing)
- bool isBody = aRefIt->second.size() > 1 || (aRefIt->second.size() == 1 &&
- aRefIt->second.front()->groupName() == ModelAPI_ResultBody::group());
- if (isBody && (isMainArg || aFoundRef == aReferences.end() ||
- aData->isPrecedingAttribute(aRefIt->first, aFoundRef->first)))
- aFoundRef = aRefIt;
-
- if (isMainArg)
- break;
+ if (theInherited) {
+ aData->referencesToObjects(aReferences);
+
+ for (ListOfReferences::const_iterator aRefIt = aReferences.begin();
+ aRefIt != aReferences.end(); ++aRefIt) {
+ bool isConcealed = aSession->validators()->isConcealed(anOwner->getKind(), aRefIt->first);
+ bool isMainArg = isConcealed &&
+ aSession->validators()->isMainArgument(anOwner->getKind(), aRefIt->first);
+ if (isConcealed) {
+ // check the referred object is a Body
+ // (for example, ExtrusionCut has a sketch as a first attribute which is concealing)
+ bool isBody = aRefIt->second.size() > 1 || (aRefIt->second.size() == 1 &&
+ aRefIt->second.front()->groupName() == ModelAPI_ResultBody::group());
+ if (isBody && (isMainArg || aFoundRef == aReferences.end() ||
+ aData->isPrecedingAttribute(aRefIt->first, aFoundRef->first)))
+ aFoundRef = aRefIt;
+
+ if (isMainArg)
+ break;
+ }
}
}
// get the result number in the feature
return std::pair<std::string, bool>(aDefaultName.str(), false);
}
+std::set<FeaturePtr> getParents(const FeaturePtr& theFeature)
+{
+ std::set<FeaturePtr> aParents;
+ for (FeaturePtr aCurFeat = theFeature; aCurFeat; ) {
+ CompositeFeaturePtr aFoundComposite;
+ const std::set<AttributePtr>& aRefs = aCurFeat->data()->refsToMe();
+ for (std::set<AttributePtr>::const_iterator anIt = aRefs.begin();
+ anIt != aRefs.end(); ++anIt) {
+ FeaturePtr aF = ModelAPI_Feature::feature((*anIt)->owner());
+ aFoundComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aF);
+ if (aFoundComposite && aFoundComposite->isSub(aCurFeat))
+ break;
+ else
+ aFoundComposite = CompositeFeaturePtr();
+ }
+
+ if (aFoundComposite) {
+ aParents.insert(aFoundComposite);
+ aCurFeat = aFoundComposite;
+ }
+ else {
+ // add the part containing high-level feature
+ SessionPtr aSession = ModelAPI_Session::get();
+ DocumentPtr aPartSetDoc = aSession->moduleDocument();
+ std::list<FeaturePtr> aPartSetFeatures = aPartSetDoc->allFeatures();
+ for (std::list<FeaturePtr>::const_iterator anIt = aPartSetFeatures.begin();
+ anIt != aPartSetFeatures.end(); ++anIt) {
+ aFoundComposite = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*anIt);
+ if (aFoundComposite && aFoundComposite->isSub(aCurFeat)) {
+ aParents.insert(aFoundComposite);
+ break;
+ }
+ }
+
+ aCurFeat = FeaturePtr();
+ }
+ }
+ return aParents;
+}
+
} // namespace ModelAPI_Tools