#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_AttributeInteger.h>
#include <ModelAPI_AttributeRefAttr.h>
#include <ModelAPI_AttributeRefAttrList.h>
bool isDumpSetName = !myEntitiesStack.empty() &&
myEntitiesStack.top().myEntity == EntityPtr(theComposite);
bool isForceModelDo = isDumpSetName &&
- (myEntitiesStack.top().myUserName || !myEntitiesStack.top().myResultsWithName.empty());
+ (myEntitiesStack.top().myUserName || !myEntitiesStack.top().myResults.empty());
// It is necessary for the sketch to create its result when complete (command "model.do()").
// This option is set by flat theDumpModelDo.
// However, nested sketches are rebuilt by parent feature, so, they do not need
anEntityNames.second.clear(); // don't dump "setName" for the entity twice
}
// dump "setName" for results
- std::list<ResultPtr>::const_iterator aResIt = aLastDumped.myResultsWithName.begin();
- std::list<ResultPtr>::const_iterator aResEnd = aLastDumped.myResultsWithName.end();
+ std::list<ResultPtr>::const_iterator aResIt = aLastDumped.myResults.begin();
+ std::list<ResultPtr>::const_iterator aResEnd = aLastDumped.myResults.end();
for (; aResIt != aResEnd; ++aResIt) {
+ // set result name
std::pair<std::string, std::string> anEntityNames = myNames[*aResIt];
if (!anEntityNames.second.empty()) {
*this << *aResIt;
- myDumpBuffer << ".result().data().setName(\"" << anEntityNames.second << "\")" << std::endl;
+ myDumpBuffer << ".setName(\"" << anEntityNames.second << "\")" << std::endl;
anEntityNames.second.clear(); // don't dump "setName" for the entity twice
}
+ // set result color
+ if (!isDefaultColor(*aResIt)) {
+ AttributeIntArrayPtr aColor = (*aResIt)->data()->intArray(ModelAPI_Result::COLOR_ID());
+ if (aColor && aColor->isInitialized()) {
+ *this << *aResIt;
+ myDumpBuffer << ".setColor(" << aColor->value(0) << ", " << aColor->value(1)
+ << ", " << aColor->value(2) << ")" << std::endl;
+ }
+ }
}
myEntitiesStack.pop();
return aFound != myNames.end();
}
+bool ModelHighAPI_Dumper::isDefaultColor(const ResultPtr& theResult) const
+{
+ AttributeIntArrayPtr aColor = theResult->data()->intArray(ModelAPI_Result::COLOR_ID());
+ if (!aColor || !aColor->isInitialized())
+ return true;
+
+ std::string aSection, aName, aDefault;
+ theResult->colorConfigInfo(aSection, aName, aDefault);
+
+ // dump current color
+ std::ostringstream aColorInfo;
+ aColorInfo << aColor->value(0) << "," << aColor->value(1) << "," << aColor->value(2);
+
+ return aDefault == aColorInfo.str();
+}
+
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const char theChar)
{
myDumpBuffer << theChar;
{
myDumpBuffer << name(theEntity);
- bool isUserDefindName = !myNames[theEntity].second.empty();
- // store results if they have user-defined names
- std::list<ResultPtr> aResultsWithUserName;
+ bool isUserDefinedName = !myNames[theEntity].second.empty();
+ // store results if they have user-defined names or colors
+ std::list<ResultPtr> aResultsWithNameOrColor;
const std::list<ResultPtr>& aResults = theEntity->results();
std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
for (; aResIt != aResults.end(); ++aResIt)
- if (!myNames[*aResIt].second.empty())
- aResultsWithUserName.push_back(*aResIt);
+ if (!myNames[*aResIt].second.empty() || !isDefaultColor(*aResIt))
+ aResultsWithNameOrColor.push_back(*aResIt);
// store just dumped entity to stack
- myEntitiesStack.push(LastDumpedEntity(theEntity, isUserDefindName, aResultsWithUserName));
+ myEntitiesStack.push(LastDumpedEntity(theEntity, isUserDefinedName, aResultsWithNameOrColor));
// remove entity from the list of not dumped items
myNotDumpedEntities.erase(theEntity);
/// Stores names of results for the given feature
void saveResultNames(const FeaturePtr& theFeature);
+ /// Check the result feature has default color
+ bool isDefaultColor(const ResultPtr& theResult) const;
+
private:
typedef std::map<EntityPtr, std::pair<std::string, std::string> > EntityNameMap;
typedef std::map<std::string, std::set<std::string> > ModulesMap;
typedef std::map<DocumentPtr, std::map<std::string, int> > NbFeaturesMap;
struct LastDumpedEntity {
- EntityPtr myEntity; // last dumped entity
- bool myUserName; // the entity hase user-defined name
- std::list<ResultPtr> myResultsWithName; // results of this entity, which has user-defined names
+ EntityPtr myEntity; ///< last dumped entity
+ bool myUserName; ///< the entity hase user-defined name
+ std::list<ResultPtr> myResults; ///< results of this entity, which has user-defined names or specific colors
LastDumpedEntity(EntityPtr theEntity, bool theUserName, const std::list<ResultPtr>& theResults)
- : myEntity(theEntity), myUserName(theUserName), myResultsWithName(theResults)
+ : myEntity(theEntity), myUserName(theUserName), myResults(theResults)
{}
};
typedef std::stack<LastDumpedEntity> DumpStack;
//--------------------------------------------------------------------------------------
#include "ModelHighAPI_Selection.h"
+#include <ModelAPI_AttributeIntArray.h>
#include <ModelAPI_AttributeSelection.h>
#include <ModelAPI_AttributeSelectionList.h>
//--------------------------------------------------------------------------------------
}
//==================================================================================================
-std::shared_ptr<ModelAPI_Result> ModelHighAPI_Selection::result() const
+void ModelHighAPI_Selection::setName(const std::string& theName)
{
if (myVariantType == VT_ResultSubShapePair)
- return myResultSubShapePair.first;
- return ResultPtr();
+ myResultSubShapePair.first->data()->setName(theName);
+}
+
+void ModelHighAPI_Selection::setColor(int theRed, int theGreen, int theBlue)
+{
+ if (myVariantType != VT_ResultSubShapePair)
+ return;
+
+ AttributeIntArrayPtr aColor =
+ myResultSubShapePair.first->data()->intArray(ModelAPI_Result::COLOR_ID());
+ aColor->setSize(3);
+ aColor->setValue(0, theRed);
+ aColor->setValue(1, theGreen);
+ aColor->setValue(2, theBlue);
}