-// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2020 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
#include <ModelAPI_ResultBody.h>
#include <ModelAPI_ResultParameter.h>
#include <ModelAPI_ResultPart.h>
+#include <ModelAPI_ResultGroup.h>
#include <ModelAPI_AttributeDocRef.h>
#include <ModelAPI_Validator.h>
#include <ModelAPI_AttributeIntArray.h>
#include <sstream>
#include <Events_Loop.h>
+#include <Locale_Convert.h>
#include <ModelAPI_Events.h>
+#include <GeomAPI_ShapeHierarchy.h>
+#include <GeomAPI_ShapeIterator.h>
+
#define RECURSE_TOP_LEVEL 50
//#define DEBUG_REMOVE_FEATURES
ObjectPtr objectByName(const DocumentPtr& theDocument, const std::string& theGroup,
const std::string& theName)
{
+ std::wstring aName = Locale::Convert::toWString(theName);
for (int anIndex = 0; anIndex < theDocument->size(theGroup); ++anIndex) {
ObjectPtr anObject = theDocument->object(theGroup, anIndex);
- if (anObject->data()->name() == theName)
+ if (anObject->data()->name() == aName)
return anObject;
}
// not found
}
//******************************************************************
-bool allDocumentsActivated(std::string& theNotActivatedNames)
+bool allDocumentsActivated(std::wstring& theNotActivatedNames)
{
- theNotActivatedNames = "";
+ theNotActivatedNames = L"";
bool anAllPartActivated = true;
DocumentPtr aRootDoc = ModelAPI_Session::get()->moduleDocument();
if (!aPart->isActivated()) {
anAllPartActivated = false;
if (!theNotActivatedNames.empty())
- theNotActivatedNames += ", ";
+ theNotActivatedNames += L", ";
theNotActivatedNames += aObject->data()->name().c_str();
}
}
}
bool removeFeaturesAndReferences(const std::set<FeaturePtr>& theFeatures,
- const bool theFlushRedisplay,
+ const bool /*theFlushRedisplay*/,
const bool theUseComposite,
const bool theUseRecursion)
{
}
else { // filter references to skip composition features of the current feature
std::set<FeaturePtr> aFilteredFeatures;
- std::set<FeaturePtr>::const_iterator anIt = aSelRefFeatures.begin(),
- aLast = aSelRefFeatures.end();
- for (; anIt != aLast; anIt++) {
- FeaturePtr aCFeature = *anIt;
+ std::set<FeaturePtr>::const_iterator aRefIt = aSelRefFeatures.begin(),
+ aRefLast = aSelRefFeatures.end();
+ for (; aRefIt != aRefLast; aRefIt++) {
+ FeaturePtr aCFeature = *aRefIt;
CompositeFeaturePtr aComposite =
std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(aCFeature);
if (aComposite.get() && aComposite->isSub(aFeature))
aResultRefList.insert(aMainRefList.begin(), aMainRefList.end());
for (; anIt != aLast; anIt++) {
FeaturePtr aFeature = *anIt;
- int aRecLevel = 0;
+ aRecLevel = 0;
#ifdef DEBUG_REMOVE_FEATURES_RECURSE
std::cout << " Ref: " << getFeatureInfo(aFeature) << std::endl;
#endif
}
}
-std::pair<std::string, bool> getDefaultName(const std::shared_ptr<ModelAPI_Result>& theResult,
+std::pair<std::wstring, bool> getDefaultName(const std::shared_ptr<ModelAPI_Result>& theResult,
const bool theInherited)
{
typedef std::list< std::pair < std::string, std::list<ObjectPtr> > > ListOfReferences;
// names of sub-solids in CompSolid should be default (for example,
// result of boolean operation 'Boolean_1_1' is a CompSolid which is renamed to 'MyBOOL',
// however, sub-elements of 'MyBOOL' should be named 'Boolean_1_1_1', 'Boolean_1_1_2' etc.)
- std::ostringstream aDefaultName;
+ std::wostringstream aDefaultName;
aDefaultName << getDefaultName(anOwnerRes).first;
aDefaultName << "_" << (bodyIndex(theResult) + 1);
- return std::pair<std::string, bool>(aDefaultName.str(), false);
+ return std::pair<std::wstring, bool>(aDefaultName.str(), false);
}
FeaturePtr anOwner = ModelAPI_Feature::feature(theResult->data()->owner());
// return name of reference result only if it has been renamed by the user,
// in other case compose a default name
if (anObjRes->data()->hasUserDefinedName()) {
- std::stringstream aName;
+ std::wstringstream aName;
aName << anObjRes->data()->name();
std::map<ResultPtr, int>::iterator aFound = aNbRefToObject.find(anObjRes);
if (aFound != aNbRefToObject.end()) {
// referring to the same shape
aName << "_" << aFound->second + 1;
}
- return std::pair<std::string, bool>(aName.str(), true);
+ return std::pair<std::wstring, bool>(aName.str(), true);
}
}
}
// compose default name by the name of the feature and the index of result
- std::stringstream aDefaultName;
+ std::wstringstream aDefaultName;
aDefaultName << anOwner->name();
// if there are several results (issue #899: any number of result),
// add unique prefix starting from second
if (anIndexInOwner > 0 || theResult->groupName() == ModelAPI_ResultBody::group())
aDefaultName << "_" << anIndexInOwner + 1;
- return std::pair<std::string, bool>(aDefaultName.str(), false);
+ return std::pair<std::wstring, bool>(aDefaultName.str(), false);
}
std::set<FeaturePtr> getParents(const FeaturePtr& theFeature)
return aParents;
}
+void fillShapeHierarchy(const GeomShapePtr& theShape,
+ const ResultPtr& theContext,
+ GeomAPI_ShapeHierarchy& theHierarchy)
+{
+ ResultBodyPtr aResCompSolidPtr = ModelAPI_Tools::bodyOwner(theContext);
+ if (aResCompSolidPtr.get()) {
+ std::shared_ptr<GeomAPI_Shape> aContextShape = aResCompSolidPtr->shape();
+ if (aContextShape->shapeType() <= GeomAPI_Shape::COMPSOLID) {
+ theHierarchy.addParent(theShape, aContextShape);
+ fillShapeHierarchy(aContextShape, aResCompSolidPtr, theHierarchy);
+ }
+ }
+}
+
+
void removeResults(const std::list<ResultPtr>& theResults)
{
// collect all documents where the results must be removed
}
}
+// used by GUI only
+// LCOV_EXCL_START
//**************************************************************
void setDeflection(ResultPtr theResult, const double theDeflection)
}
}
-// used by GUI only
-// LCOV_EXCL_START
double getDeflection(const std::shared_ptr<ModelAPI_Result>& theResult)
{
double aDeflection = -1;
}
return aTransparency;
}
-// LCOV_EXCL_STOP
void copyVisualizationAttrs(
std::shared_ptr<ModelAPI_Result> theSource, std::shared_ptr<ModelAPI_Result> theDest)
if (aFeat.get() && (theFeatureKind.empty() || aFeat->getKind() == theFeatureKind))
aResSet.insert(aFeat);
}
+ // check also Group-operations that may refer to groups - add them for theFeatureKind "Group"
+ if (theFeatureKind == "Group") {
+ std::set<FeaturePtr> aGroupOperations;
+ for(bool aNeedIterate = true; aNeedIterate; ) {
+ std::set<FeaturePtr>::iterator aResIter = aResSet.begin();
+ for(; aResIter != aResSet.end(); aResIter++) {
+ std::list<ResultPtr>::const_iterator aGroupRes = (*aResIter)->results().cbegin();
+ for(; aGroupRes != (*aResIter)->results().cend(); aGroupRes++) {
+ const std::set<AttributePtr>& aGroupRefs = (*aGroupRes)->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator aRefIt = aGroupRefs.cbegin();
+ for(; aRefIt != aGroupRefs.cend(); aRefIt++) {
+ FeaturePtr aFeat = std::dynamic_pointer_cast<ModelAPI_Feature>((*aRefIt)->owner());
+ if (aFeat.get() && !aGroupOperations.count(aFeat) && !aFeat->results().empty() &&
+ aFeat->firstResult()->groupName() == ModelAPI_ResultGroup::group()) {
+ // iterate results of this group operation because it may be without theTarget shape
+ GeomShapePtr aTargetShape = theTarget->shape();
+ bool anIsIn = false;
+ std::list<ResultPtr>::const_iterator anOpRes = aFeat->results().cbegin();
+ for(; anOpRes != aFeat->results().cend() && !anIsIn; anOpRes++) {
+ GeomShapePtr anOpShape = (*anOpRes)->shape();
+ if (!anOpShape.get() || anOpShape->isNull())
+ continue;
+ for(GeomAPI_ShapeIterator aSubIt(anOpShape); aSubIt.more(); aSubIt.next()) {
+ if (aTargetShape->isSubShape(aSubIt.current(), false)) {
+ anIsIn = true;
+ break;
+ }
+ }
+ }
+ if (anIsIn)
+ aGroupOperations.insert(aFeat);
+ }
+ }
+ }
+ }
+ // insert all new group operations into result and if they are, check for next dependencies
+ aNeedIterate = false;
+ std::set<FeaturePtr>::iterator aGroupOpIter = aGroupOperations.begin();
+ for(; aGroupOpIter != aGroupOperations.end(); aGroupOpIter++) {
+ if (aResSet.find(*aGroupOpIter) == aResSet.end()) {
+ aResSet.insert(*aGroupOpIter);
+ aNeedIterate = true;
+ }
+ }
+ }
+ }
std::list<FeaturePtr> aResList;
std::set<FeaturePtr>::iterator aResIter = aResSet.begin();
return aResList;
}
+// LCOV_EXCL_STOP
+
} // namespace ModelAPI_Tools