#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_Tools.h>
+#include <ModelAPI_ResultGroup.h>
#include <Events_Loop.h>
#include <Config_Translator.h>
+#include <Config_PropManager.h>
void ModelAPI_Feature::setError(const std::string& theError,
bool isSend,
// in any case result becomes enabled
if (!isDisabled()) // disabled feature may be executed when it is added as not enabled (#2078)
theResult->setDisabled(theResult, false);
+
+ bool anIsAutoColor = Config_PropManager::boolean("Visualization", "result_group_Auto_color");
+
+ if (anIsAutoColor && theResult->groupName() == ModelAPI_ResultGroup::group()) {
+ std::vector<int> aColor;
+ ModelAPI_Tools::findRandomColor(aColor);
+ ModelAPI_Tools::setColor(theResult, aColor);
+ }
}
void ModelAPI_Feature::setResult(const std::shared_ptr<ModelAPI_Result>& theResult,
return aResList;
}
+// contains global cash for integer index of the color -> RGB of this color
+static std::map<int, std::vector<int> > myColorMap;
+
+void appendValues(std::vector<int>& theRGB, const int theRed, const int theGreen, const int theBlue)
+{
+ theRGB.push_back(theRed);
+ theRGB.push_back(theGreen);
+ theRGB.push_back(theBlue);
+}
+
+bool containsValues(std::map<int, std::vector<int> >& theColorMap, std::vector<int>& theValues)
+{
+ std::map<int, std::vector<int> >::const_iterator anIt = theColorMap.begin(),
+ aLast = theColorMap.end();
+ bool isFound = false;
+ for (; anIt != aLast && !isFound; anIt++) {
+ std::vector<int> aValues = anIt->second;
+ isFound = aValues[0] == theValues[0] &&
+ aValues[1] == theValues[1] &&
+ aValues[2] == theValues[2];
+ }
+ return isFound;
+}
+
+std::vector<int> HSVtoRGB(int theH, int theS, int theV)
+{
+ std::vector<int> aRGB;
+ if (theH < 0 || theH > 360 ||
+ theS < 0 || theS > 100 ||
+ theV < 0 || theV > 100)
+ return aRGB;
+
+ int aHi = (int)theH/60;
+
+ double aV = theV;
+ double aVmin = (100 - theS)*theV/100;
+
+ double anA = (theV - aVmin)* (theH % 60) / 60;
+
+ double aVinc = aVmin + anA;
+ double aVdec = theV - anA;
+
+ double aPercentToValue = 255./100;
+ int aV_int = (int)(aV*aPercentToValue);
+ int aVinc_int = (int)(aVinc*aPercentToValue);
+ int aVmin_int = (int)(aVmin*aPercentToValue);
+ int aVdec_int = (int)(aVdec*aPercentToValue);
+
+ switch(aHi) {
+ case 0: appendValues(aRGB, aV_int, aVinc_int, aVmin_int); break;
+ case 1: appendValues(aRGB, aVdec_int, aV_int, aVmin_int); break;
+ case 2: appendValues(aRGB, aVmin_int, aV_int, aVinc_int); break;
+ case 3: appendValues(aRGB, aVmin_int, aVdec_int, aV_int); break;
+ case 4: appendValues(aRGB, aVinc_int, aVmin_int, aV_int); break;
+ case 5: appendValues(aRGB, aV_int, aVmin_int, aVdec_int); break;
+ default: break;
+ }
+ return aRGB;
+}
+
+
+void fillColorMap()
+{
+ if (!myColorMap.empty())
+ return;
+
+ int i = 0;
+ for (int s = 100; s > 0; s = s - 50)
+ {
+ for (int v = 100; v >= 40; v = v - 20)
+ {
+ for (int h = 0; h < 359 ; h = h + 60)
+ {
+ std::vector<int> aColor = HSVtoRGB(h, s, v);
+ if (containsValues(myColorMap, aColor))
+ continue;
+ myColorMap[i] = aColor;
+ i++;
+ }
+ }
+ }
+}
+
+void findRandomColor(std::vector<int>& theValues)
+{
+ theValues.clear();
+ if (myColorMap.empty()) {
+ fillColorMap();
+ }
+
+ size_t aSize = myColorMap.size();
+ int anIndex = rand() % aSize;
+ if (myColorMap.find(anIndex) != myColorMap.end()) {
+ theValues = myColorMap.at(anIndex);
+ }
+}
+
// LCOV_EXCL_STOP
} // namespace ModelAPI_Tools
MODELAPI_EXPORT std::list<std::shared_ptr<ModelAPI_Feature> > referencedFeatures(
std::shared_ptr<ModelAPI_Result> theTarget, const std::string& theFeatureKind,
const bool theSortResults);
+
+
+/*! Returns a container with the current color value.
+* These are tree int values for RGB definition.
+* It returns the next random color.
+* \param theValues vector of values
+*/
+MODELAPI_EXPORT void findRandomColor(std::vector<int>& theValues);
+
}
#endif
Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
Config_Prop::Color, ModelAPI_ResultGroup::DEFAULT_COLOR());
+ Config_PropManager::registerProp("Visualization", "result_group_Auto_color", "Auto color",
+ Config_Prop::Boolean, "false");
+
Config_PropManager::registerProp("Visualization", "result_construction_color",
"Construction color",
Config_Prop::Color,
CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
if (aSketch.get()) {
ModuleBase_Operation* anOperation = myWorkshop->currentOperation();
- if (PartSet_SketcherMgr::isSketchOperation(anOperation) &&
- mySketchMgr->previewSketchPlane()->isDisplayed())
+ if (PartSet_SketcherMgr::isSketchOperation(anOperation))
mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
}
}
return aValues;
}
-// contains global cash for integer index of the color -> RGB of this color
-static std::map<int, std::vector<int> > myColorMap;
-
-void appendValues(std::vector<int>& theRGB, const int theRed, const int theGreen, const int theBlue)
-{
- theRGB.push_back(theRed);
- theRGB.push_back(theGreen);
- theRGB.push_back(theBlue);
-}
-
-bool containsValues(std::map<int, std::vector<int> >& theColorMap, std::vector<int>& theValues)
-{
- std::map<int, std::vector<int> >::const_iterator anIt = theColorMap.begin(),
- aLast = theColorMap.end();
- bool isFound = false;
- for (; anIt != aLast && !isFound; anIt++) {
- std::vector<int> aValues = anIt->second;
- isFound = aValues[0] == theValues[0] &&
- aValues[1] == theValues[1] &&
- aValues[2] == theValues[2];
- }
- return isFound;
-}
-
-std::vector<int> HSVtoRGB(int theH, int theS, int theV)
-{
- std::vector<int> aRGB;
- if (theH < 0 || theH > 360 ||
- theS < 0 || theS > 100 ||
- theV < 0 || theV > 100)
- return aRGB;
-
- int aHi = (int)theH/60;
-
- double aV = theV;
- double aVmin = (100 - theS)*theV/100;
-
- double anA = (theV - aVmin)* (theH % 60) / 60;
-
- double aVinc = aVmin + anA;
- double aVdec = theV - anA;
-
- double aPercentToValue = 255./100;
- int aV_int = (int)(aV*aPercentToValue);
- int aVinc_int = (int)(aVinc*aPercentToValue);
- int aVmin_int = (int)(aVmin*aPercentToValue);
- int aVdec_int = (int)(aVdec*aPercentToValue);
-
- switch(aHi) {
- case 0: appendValues(aRGB, aV_int, aVinc_int, aVmin_int); break;
- case 1: appendValues(aRGB, aVdec_int, aV_int, aVmin_int); break;
- case 2: appendValues(aRGB, aVmin_int, aV_int, aVinc_int); break;
- case 3: appendValues(aRGB, aVmin_int, aVdec_int, aV_int); break;
- case 4: appendValues(aRGB, aVinc_int, aVmin_int, aV_int); break;
- case 5: appendValues(aRGB, aV_int, aVmin_int, aVdec_int); break;
- default: break;
- }
- return aRGB;
-}
-
-
-void fillColorMap()
-{
- if (!myColorMap.empty())
- return;
-
- int i = 0;
- for (int s = 100; s > 0; s = s - 50)
- {
- for (int v = 100; v >= 40; v = v - 20)
- {
- for (int h = 0; h < 359 ; h = h + 60)
- {
- std::vector<int> aColor = HSVtoRGB(h, s, v);
- if (containsValues(myColorMap, aColor))
- continue;
- myColorMap[i] = aColor;
- i++;
- }
- }
- }
-}
-
-void findRandomColor(std::vector<int>& theValues)
-{
- theValues.clear();
- if (myColorMap.empty()) {
- fillColorMap();
- }
-
- size_t aSize = myColorMap.size();
- int anIndex = rand() % aSize;
- if (myColorMap.find(anIndex) != myColorMap.end()) {
- theValues = myColorMap.at(anIndex);
- }
-}
std::vector<int> XGUI_ColorDialog::getRandomColor() const
{
std::vector<int> aValues;
if (isRandomColor()) {
- findRandomColor(aValues);
+ ModelAPI_Tools::findRandomColor(aValues);
}
return aValues;
}
-std::vector<int> XGUI_ColorDialog::randomColor()
-{
- std::vector<int> aValues;
- findRandomColor(aValues);
- return aValues;
-}
/// \return a vector of values
std::vector<int> getRandomColor() const;
- /// Returns a container with the current color value.
- /// These are tree int values for RGB definition.
- /// It returns the next random color.
- /// \return a vector of values
- static std::vector<int> randomColor();
-
private:
QButtonGroup* myButtonGroup; /// a group, contained random and certain color radio button choice
QtxColorButton* myColorButton; /// a control to select a color
// 3. abort the previous operation and start a new one
SessionPtr aMgr = ModelAPI_Session::get();
QString aDescription = contextMenuMgr()->action("COLOR_CMD")->text();
+
aMgr->startOperation(aDescription.toStdString());
// 4. set the value to all results
if (!abortAllOperations())
return;
- std::vector<int> aColor = XGUI_ColorDialog::randomColor();
+ std::vector<int> aColor;
+ ModelAPI_Tools::findRandomColor(aColor);
// abort the previous operation and start a new one
SessionPtr aMgr = ModelAPI_Session::get();
QString aDescription = contextMenuMgr()->action("AUTOCOLOR_CMD")->text();
aMgr->startOperation(aDescription.toStdString());
- Config_Prop* aProp = Config_PropManager::findProp("Visualization", "result_group_color");
+ Config_Prop* aProp = Config_PropManager::findProp("Visualization", "result_group_Auto_color");
+ bool anIsAutoColor = Config_PropManager::boolean("Visualization", "result_group_Auto_color");
- if( aDescription == tr("Disable auto color"))
- {
- contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Auto color") );
-
- aProp->setValue(ModelAPI_ResultGroup::DEFAULT_COLOR());
-
- }else{
- std::stringstream streamColor;
- streamColor<< aColor[0] <<","<< aColor[1] <<"," <<aColor[2];
-
- /*Config_PropManager::registerProp("Visualization", "result_group_color", "Group color",
- Config_Prop::Color, streamColor.str());*/
-
- aProp->setValue(streamColor.str());
-
- /* set the value to all results
- foreach(ObjectPtr anObj, theObjects) {
- ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
- if (aResult.get() != NULL) {
- //aResult->setAutocolor(true);
- //ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
- ResultBodyPtr aBodyResult = ModelAPI_Tools::bodyOwner(aResult,true);
- if (aBodyResult.get() != NULL) { // change colors for all sub-solids
- std::list<ResultPtr> allRes;
- ModelAPI_Tools::allSubs(aBodyResult, allRes);
- for(std::list<ResultPtr>::iterator aRes = allRes.begin(); aRes != allRes.end(); aRes++) {
- //(*aRes)->setAutocolor(true);
- ModelAPI_Tools::setColor(*aRes, aColor);
+ if (anIsAutoColor) {
+ contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Auto color"));
+ aProp->setValue("false");
+ } else {
+ // set the value to all results
+ foreach (ObjectPtr anObj, theObjects) {
+ DocumentPtr aDocument = anObj->document();
+ std::list<FeaturePtr> anAllFeatures = allFeatures(aDocument);
+ // find the object iterator
+ std::list<FeaturePtr>::iterator aObjectIt = anAllFeatures.begin();
+ for (; aObjectIt != anAllFeatures.end(); ++ aObjectIt) {
+ FeaturePtr aFeature = *aObjectIt;
+ if (aFeature.get()) {
+ std::list<ResultPtr> aResults;
+ ModelAPI_Tools::allResults(aFeature, aResults);
+ std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aIt;
+ for (aIt = aResults.cbegin(); aIt != aResults.cend(); aIt++) {
+ ResultPtr aGroupResult = *aIt;
+ if (aGroupResult.get() && aGroupResult->groupName() == ModelAPI_ResultGroup::group()) {
+ ModelAPI_Tools::findRandomColor(aColor);
+ ModelAPI_Tools::setColor(aGroupResult, aColor);
+ }
}
}
- ModelAPI_Tools::setColor(aResult, aColor);
}
- }*/
+ }
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
aMgr->finishOperation();
updateCommandStatus();
myViewerProxy->update();
- contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Disable auto color") );
+ contextMenuMgr()->action("AUTOCOLOR_CMD")->setText(tr("Disable auto color"));
+ aProp->setValue("true");
}
}
/// Sets the granted operations for the parameter operation. Firstly, it finds the nested features
/// and set them into the operation. Secondly, it asks the module about ids of granted operations.
/// \param theOperation an operation
- void setGrantedFeatures(ModuleBase_Operation* theOperation);
+ void setGrantedFeatures(ModuleBase_Operation* theOperation);
private:
/// Display results from document