From 87b34b04fdb7018486c416b67eee557fa92023b7 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Tue, 27 Feb 2024 11:18:37 +0100 Subject: [PATCH 1/4] Refactor simulation Colors.h & pixmap generation in runSofa. --- .../sofa/gui/qt/GraphListenerQListView.cpp | 396 ++++++++---------- .../Core/src/sofa/simulation/Colors.h | 62 +-- .../src/sofa/simulation/ExportDotVisitor.cpp | 34 +- 3 files changed, 232 insertions(+), 260 deletions(-) diff --git a/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp b/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp index 2b529ba25fa..8cea765d7a3 100644 --- a/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp +++ b/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp @@ -32,9 +32,10 @@ #include #include #include - +#include using sofa::component::sceneutility::InfoComponent ; +using sofa::simulation::Colors; #include "resources/icons/iconmultinode.xpm" #include "resources/icons/iconnode.xpm" @@ -53,10 +54,7 @@ using namespace sofa::core::objectmodel; namespace sofa::gui::qt { - - //*********************************************************************************************************** - static const int iconWidth=8; static const int iconHeight=16; static const int iconMargin=6; @@ -69,60 +67,95 @@ static int hexval(char c) else return 0; } -const std::string getClass(core::objectmodel::Base* obj){ - if (obj->toBaseNode()) - { - return "Node"; - } - if (obj->toBaseObject()) +void addOverlayToImage(QImage* image, const QImage* overlay, int width, int height) +{ + for (int x=0;xtoContextObject()) - return "Context"; - if (obj->toBehaviorModel()) - return "BehaviorModel"; - if (obj->toCollisionModel()) - return "CollisionModel"; - if (obj->toBaseMechanicalState()) - return "MechanicalModel"; - if (obj->toBaseProjectiveConstraintSet()) - return "ProjectiveConstraintSet"; - if (obj->toBaseConstraintSet()) - return "BaseConstraintSet"; - if (obj->toBaseInteractionForceField() && - obj->toBaseInteractionForceField()->getMechModel1()!=obj->toBaseInteractionForceField()->getMechModel2()) - return "InteractionForceField"; - if (obj->toBaseForceField()) - return "ForceField"; - if (obj->toBaseAnimationLoop() - || obj->toOdeSolver()) - return "Solver"; - if (obj->toPipeline() - || obj->toIntersection() - || obj->toDetection() - || obj->toContactManager() - || obj->toCollisionGroupManager()) - return "Collision"; - if (obj->toBaseMapping()) - return "Mapping"; - if (obj->toBaseMass()) - return "Mass"; - if (obj->toTopology () - || obj->toBaseTopologyObject() ) - return "Topology"; - if (obj->toBaseLoader()) - return "Loader"; - if (obj->toConfigurationSetting()) - return "Configuration"; - if (obj->toVisualModel()) - return "Visual"; + for(int y=0;ypixel(x,y)) == 255 ) + image->setPixel(x, y, overlay->pixel(x,y) ); + } } - return "Other"; } +/// get the appropriate pixmap for a given state. If the pixmap does not exists, then +/// the appropriate one is generated and stored in a cache for further re-use. +QPixmap* getPixmapForFlags(unsigned int flags, std::map& pixmaps) +{ + // is there is not pixmap for such state, then generates one + if (pixmaps.find(flags) == pixmaps.end()) + { + if(flags&(1<(iconnode_xpm); + // Create a new image from pixmap + const QImage timg(icon); + QImage image {timg.convertToFormat(QImage::Format_ARGB32)}; + pixmaps[flags] = new QPixmap(QPixmap::fromImage(image)); + }else if(flags & (1 << Colors::OBJECT)) + { + const int iconWidth=16; + const int iconHeight=16; + const int iconMargin=5; -QPixmap* getPixmap(core::objectmodel::Base* obj, bool haveInfo, bool haveWarning, bool haveErrors) + QImage img { iconWidth,iconHeight,QImage::Format_ARGB32 }; + img.fill(qRgba(0,0,0,0)); + + // draw vertical black lines + for (int y=iconMargin ; y < iconHeight-1 ; y++) + { + img.setPixel(0,y,qRgba(0,0,0,255)); + img.setPixel(iconWidth-iconMargin,y,qRgba(0,0,0,255)); + } + + // draw vertical black horizontal lines + for (int x=0 ; x < iconWidth-iconMargin ; x++) + { + img.setPixel(x,iconMargin,qRgba(0,0,0,255)); + img.setPixel(x,iconHeight-1,qRgba(0,0,0,255)); + } + + // select the largest "type" for color. + int nc = 0; + for (int i=0; i(iconsleep_xpm)); + static QImage imgSleeping = pixSleeping.toImage(); + static QPixmap pixInfo(reinterpret_cast(iconinfo_xpm)); static QImage imgInfo8 = pixInfo.scaledToWidth(16).toImage(); @@ -132,186 +165,119 @@ QPixmap* getPixmap(core::objectmodel::Base* obj, bool haveInfo, bool haveWarning static QPixmap pixWarning(reinterpret_cast(iconwarning_xpm)); static QImage imgWarning8 = pixWarning.scaledToWidth(16).toImage(); + static std::map pixmaps; - using namespace sofa::simulation::Colors; - unsigned int flags = 0; + unsigned int flags=typeFlags; + if(isSleeping) + flags |= 1 << (Colors::ALLCOLORS+1); - if (obj->toBaseNode()) - { - - const char** icon = reinterpret_cast(iconsleep_xpm); - if( !obj->toBaseNode()->getContext()->isSleeping() ){ - icon = reinterpret_cast(iconnode_xpm) ; - flags = 1 ; - } + if(haveInfo) + flags |= 1 << (Colors::ALLCOLORS+2); - if(haveInfo) - flags |= 1 << (2) ; + if(haveWarning) + flags |= 1 << (Colors::ALLCOLORS+3); - if(haveWarning) - flags |= 1 << (3) ; + if(haveErrors) + flags |= 1 << (Colors::ALLCOLORS+4); - if(haveErrors) - flags |= 1 << (4) ; + // is there is a pixmap for such type+state, if so then returns it + if (pixmaps.find(flags) != pixmaps.end()) + return pixmaps[flags]; + // if there is no such pixmap creates a new one by combining the object type with its status as overlay. - static std::map pixmaps; - if (!pixmaps.count(flags)) - { - /// Create a new image from pixmap - const QImage timg(icon) ; - QImage* img = new QImage(timg.convertToFormat(QImage::Format_ARGB32)) ; - - const QImage* overlaysymbol=nullptr; - if( haveInfo ) - overlaysymbol = &imgInfo8 ; - if( haveWarning ) - overlaysymbol = &imgWarning8 ; - if( haveErrors ) - overlaysymbol = &imgError8 ; - - if(overlaysymbol){ - for (int x=0;x<16;x++) - { - for(int y=0;y<16;y++) - { - if( qAlpha(overlaysymbol->pixel(x,y)) == 255 ){ - img->setPixel(x, y, overlaysymbol->pixel(x,y) ); - } - } - } - } - pixmaps[flags] = new QPixmap(QPixmap::fromImage(*img)); - } + // get the background pixmap + auto timg = getPixmapForFlags(typeFlags, pixmaps)->toImage() ; + QImage image {timg.convertToFormat(QImage::Format_ARGB32)}; - return pixmaps[flags] ; - } - else if (obj->toBaseObject()) - { - if (obj->toContextObject()) - flags |= 1 << CONTEXT; - if (obj->toBehaviorModel()) - flags |= 1 << BMODEL; - if (obj->toCollisionModel()) - flags |= 1 << CMODEL; - if (obj->toBaseMechanicalState()) - flags |= 1 << MMODEL; - if (obj->toBaseProjectiveConstraintSet()) - flags |= 1 << PROJECTIVECONSTRAINTSET; - if (obj->toBaseConstraintSet()) - flags |= 1 << CONSTRAINTSET; - if (obj->toBaseInteractionForceField() && - obj->toBaseInteractionForceField()->getMechModel1()!=obj->toBaseInteractionForceField()->getMechModel2()) - flags |= 1 << IFFIELD; - else if (obj->toBaseForceField()) - flags |= 1 << FFIELD; - if (obj->toBaseAnimationLoop() - || obj->toOdeSolver()) - flags |= 1 << SOLVER; - if (obj->toPipeline() - || obj->toIntersection() - || obj->toDetection() - || obj->toContactManager() - || obj->toCollisionGroupManager()) - flags |= 1 << COLLISION; - if (obj->toBaseMapping()) - flags |= 1 << ((obj->toBaseMapping())->isMechanical()?MMAPPING:MAPPING); - if (obj->toBaseMass()) - flags |= 1 << MASS; - if (obj->toTopology () - || obj->toBaseTopologyObject() ) - flags |= 1 << TOPOLOGY; - if (obj->toBaseLoader()) - flags |= 1 << LOADER; - if (obj->toConfigurationSetting()) - flags |= 1 << CONFIGURATIONSETTING; - if (obj->toVisualModel() && !flags) - flags |= 1 << VMODEL; - if (!flags) - flags |= 1 << OBJECT; - } - else return nullptr; + // generates one our of the base flags with the state overlay + if(isSleeping) + addOverlayToImage(&image, &imgSleeping, imgSleeping.width(), imgSleeping.height()); - if(haveInfo) - flags |= 1 << (ALLCOLORS+1) ; + const QImage* overlay=nullptr; + if( haveInfo ) + overlay = &imgInfo8; + if( haveWarning ) + overlay = &imgWarning8; + if( haveErrors ) + overlay = &imgError8; - if(haveWarning) - flags |= 1 << (ALLCOLORS+1) ; + if(overlay) + addOverlayToImage(&image, overlay, 16, 16); - if(haveErrors) - flags |= 1 << (ALLCOLORS+1) ; + pixmaps[flags] = new QPixmap(QPixmap::fromImage(image)); + return pixmaps[flags]; +} - static std::map pixmaps; - if (!pixmaps.count(flags)) - { - int nc = 0; - for (int i=0; isetAlphaBuffer(true); - img->fill(qRgba(0,0,0,0)); - // Workaround for qt 3.x where fill() does not set the alpha channel - for (int y=0 ; y < iconHeight ; y++) - for (int x=0 ; x < nx ; x++) - img->setPixel(x,y,qRgba(0,0,0,0)); - - // left Line - for (int y=iconMargin ; y < iconHeight ; y++) - img->setPixel(0,y,qRgba(0,0,0,255)); - - nc = 0; - for (int i=0; isetPixel(x,iconMargin-1,qRgba(0,0,0,255)); - img->setPixel(x,iconHeight-1,qRgba(0,0,0,255)); - for (int y=iconMargin ; y < iconHeight-1 ; y++) - img->setPixel(x,y,qRgba(r,g,b,a)); - } - ++nc; - } - // right line Line - for (int y=iconMargin ; y < iconHeight ; y++) - img->setPixel(2+iconWidth*nc-1,y,qRgba(0,0,0,255)); +QPixmap* getBaseNodePixmap(core::objectmodel::BaseNode* node, bool haveInfo, bool haveWarning, bool haveErrors) +{ + unsigned int flags = 1 << Colors::NODE; + return getPixmapForFlagsAndState(flags, + node->getContext()->isSleeping(), + haveInfo, haveWarning, haveErrors); +} - const QImage* overlaysymbol=nullptr; - if( haveInfo ) - overlaysymbol = &imgInfo8 ; - if( haveWarning ) - overlaysymbol = &imgWarning8 ; - if( haveErrors ) - overlaysymbol = &imgError8 ; +QPixmap* getBaseObjectPixmap(core::objectmodel::BaseObject* obj, bool haveInfo, bool haveWarning, bool haveErrors) +{ + unsigned int flags = 0; - if(overlaysymbol){ - for (int x=0;x<16;x++) - { - for(int y=0;y<16;y++) - { - if( qAlpha(overlaysymbol->pixel(x,y)) == 255 ) - img->setPixel(x, y, overlaysymbol->pixel(x,y) ); - } - } - } + flags |= 1 << Colors::OBJECT; + if (obj->toContextObject()) + flags |= 1 << Colors::CONTEXT; + if (obj->toBehaviorModel()) + flags |= 1 << Colors::BMODEL; + if (obj->toCollisionModel()) + flags |= 1 << Colors::CMODEL; + if (obj->toBaseMechanicalState()) + flags |= 1 << Colors::MMODEL; + if (obj->toBaseProjectiveConstraintSet()) + flags |= 1 << Colors::PROJECTIVECONSTRAINTSET; + if (obj->toBaseConstraintSet()) + flags |= 1 << Colors::CONSTRAINTSET; + if (obj->toBaseInteractionForceField() && + obj->toBaseInteractionForceField()->getMechModel1()!=obj->toBaseInteractionForceField()->getMechModel2()) + flags |= 1 << Colors::IFFIELD; + else if (obj->toBaseForceField()) + flags |= 1 << Colors::FFIELD; + if (obj->toBaseAnimationLoop() + || obj->toOdeSolver()) + flags |= 1 << Colors::SOLVER; + if (obj->toPipeline() + || obj->toIntersection() + || obj->toDetection() + || obj->toContactManager() + || obj->toCollisionGroupManager()) + flags |= 1 << Colors::COLLISION; + if (obj->toBaseMapping() && obj->toBaseMapping()->isMechanical()) + flags |= (1 << Colors::MMAPPING); + if (obj->toBaseMapping()) + flags |= (1 << Colors::MAPPING); + if (obj->toBaseMass()) + flags |= 1 << Colors::MASS; + if (obj->toTopology () + || obj->toBaseTopologyObject() ) + flags |= 1 << Colors::TOPOLOGY; + if (obj->toBaseLoader()) + flags |= 1 << Colors::LOADER; + if (obj->toConfigurationSetting()) + flags |= 1 << Colors::CONFIGURATIONSETTING; + if (obj->toVisualModel()) + flags |= 1 << Colors::VMODEL; + + return getPixmapForFlagsAndState(flags, false, haveInfo, haveWarning, haveErrors); +} - pixmaps[flags] = new QPixmap(QPixmap::fromImage(*img)); - delete img; - } - return pixmaps[flags]; +QPixmap* getPixmap(core::objectmodel::Base* obj, bool haveInfo, bool haveWarning, bool haveErrors) +{ + if (obj->toBaseNode()) + return getBaseNodePixmap(obj->toBaseNode(), haveInfo,haveWarning, haveErrors); + + if (obj->toBaseObject()) + return getBaseObjectPixmap(obj->toBaseObject(), haveInfo,haveWarning, haveErrors); + + return nullptr; } void setMessageIconFrom(QTreeWidgetItem* item, Base* object) @@ -404,7 +370,7 @@ void GraphListenerQListView::onBeginAddChild(Node* parent, Node* child) // Node with multiple parents if (parent && - parent != findObject(item->parent()) ) + parent != findObject(item->parent()) ) { // check that the multinode have not been added yet // i.e. verify that all every item equivalent to current 'item' (in nodeWithMultipleParents) do not have the same 'parent' diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.h index f305ecd50bd..651a4c17956 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.h @@ -26,12 +26,13 @@ #include -namespace sofa::simulation::Colors +namespace sofa::simulation { -enum +typedef enum { - NODE, + NODE = 0, + PREFAB, OBJECT, CONTEXT, BMODEL, @@ -51,14 +52,15 @@ enum LOADER , CONFIGURATIONSETTING, ALLCOLORS -}; +} Colors; // See http://www.graphviz.org/doc/info/colors.html // The following is mostly the "set312" colors -static const char* COLOR[ALLCOLORS]= +static const char* DEFAULT_COLOR[ALLCOLORS]= { /*Node =*/ "#dedede", // color 9 + /*Prefab =*/ "#dedede", // color 9 /*Object =*/ "#ffffff", // white /*Context =*/ "#d7191c", // color spectral4/1 /*BehaviorModel =*/ "#93ff49", // color 7 (brighter) @@ -79,30 +81,36 @@ static const char* COLOR[ALLCOLORS]= /*ConfigurationSetting =*/ "#aaaaaa", // pale pink }; -inline const char* getColor(const char* classname) +inline const char* getDefaultColor(unsigned int index, const char* defaultValue="") { - if (!strcmp(classname,"BaseNode")) return COLOR[NODE]; - if (!strcmp(classname,"BaseObject")) return COLOR[OBJECT]; - if (!strcmp(classname,"ContextObject")) return COLOR[CONTEXT]; - if (!strcmp(classname,"BehaviorModel")) return COLOR[BMODEL]; - if (!strcmp(classname,"CollisionModel")) return COLOR[CMODEL]; - if (!strcmp(classname,"MechanicalState")) return COLOR[MMODEL]; - if (!strcmp(classname,"ProjectiveConstraintSet")) return COLOR[PROJECTIVECONSTRAINTSET]; - if (!strcmp(classname,"ConstraintSet")) return COLOR[CONSTRAINTSET]; - if (!strcmp(classname,"InteractionForceField")) return COLOR[IFFIELD]; - if (!strcmp(classname,"ForceField")) return COLOR[FFIELD]; - if (!strcmp(classname,"BaseAnimationLoop")) return COLOR[SOLVER]; - if (!strcmp(classname,"OdeSolver")) return COLOR[SOLVER]; - if (!strcmp(classname,"CollisionPipeline")) return COLOR[COLLISION]; - if (!strcmp(classname,"MechanicalMapping")) return COLOR[MMAPPING]; - if (!strcmp(classname,"Mapping")) return COLOR[MAPPING]; - if (!strcmp(classname,"Mass")) return COLOR[MASS]; - if (!strcmp(classname,"Topology")) return COLOR[TOPOLOGY]; - if (!strcmp(classname,"VisualModel")) return COLOR[VMODEL]; - if (!strcmp(classname,"Loader")) return COLOR[LOADER]; - if (!strcmp(classname,"ConfigurationSetting")) return COLOR[CONFIGURATIONSETTING]; - return ""; + if(index >= Colors::ALLCOLORS) + return defaultValue; + return DEFAULT_COLOR[index]; +} +inline const char* getDefaultColor(const char* classname, const char* defaultValue="") +{ + if (!strcmp(classname,"BaseNode")) return DEFAULT_COLOR[NODE]; + if (!strcmp(classname,"BaseObject")) return DEFAULT_COLOR[OBJECT]; + if (!strcmp(classname,"ContextObject")) return DEFAULT_COLOR[CONTEXT]; + if (!strcmp(classname,"BehaviorModel")) return DEFAULT_COLOR[BMODEL]; + if (!strcmp(classname,"CollisionModel")) return DEFAULT_COLOR[CMODEL]; + if (!strcmp(classname,"MechanicalState")) return DEFAULT_COLOR[MMODEL]; + if (!strcmp(classname,"ProjectiveConstraintSet")) return DEFAULT_COLOR[PROJECTIVECONSTRAINTSET]; + if (!strcmp(classname,"ConstraintSet")) return DEFAULT_COLOR[CONSTRAINTSET]; + if (!strcmp(classname,"InteractionForceField")) return DEFAULT_COLOR[IFFIELD]; + if (!strcmp(classname,"ForceField")) return DEFAULT_COLOR[FFIELD]; + if (!strcmp(classname,"BaseAnimationLoop")) return DEFAULT_COLOR[SOLVER]; + if (!strcmp(classname,"OdeSolver")) return DEFAULT_COLOR[SOLVER]; + if (!strcmp(classname,"CollisionPipeline")) return DEFAULT_COLOR[COLLISION]; + if (!strcmp(classname,"MechanicalMapping")) return DEFAULT_COLOR[MMAPPING]; + if (!strcmp(classname,"Mapping")) return DEFAULT_COLOR[MAPPING]; + if (!strcmp(classname,"Mass")) return DEFAULT_COLOR[MASS]; + if (!strcmp(classname,"Topology")) return DEFAULT_COLOR[TOPOLOGY]; + if (!strcmp(classname,"VisualModel")) return DEFAULT_COLOR[VMODEL]; + if (!strcmp(classname,"Loader")) return DEFAULT_COLOR[LOADER]; + if (!strcmp(classname,"ConfigurationSetting")) return DEFAULT_COLOR[CONFIGURATIONSETTING]; + return defaultValue; } } diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/ExportDotVisitor.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/ExportDotVisitor.cpp index d967cea7992..aa69ace2729 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/ExportDotVisitor.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/ExportDotVisitor.cpp @@ -71,11 +71,10 @@ ExportDotVisitor::~ExportDotVisitor() /// Test if a node should be displayed bool ExportDotVisitor::display(Node* node, const char **color) { - using namespace Colors; if (!node) return false; if (showNode) { - if (color) *color = COLOR[NODE]; + if (color) *color = getDefaultColor(NODE); return true; } else @@ -85,42 +84,41 @@ bool ExportDotVisitor::display(Node* node, const char **color) /// Test if an object should be displayed bool ExportDotVisitor::display(core::objectmodel::BaseObject* obj, const char **color) { - using namespace Colors; const char* c = nullptr; if (color==nullptr) color=&c; if (!obj) return false; if (!showObject) return false; - *color = COLOR[OBJECT]; + *color = getDefaultColor(OBJECT); bool show = false; bool hide = false; if (obj->toBaseMechanicalState()) { - if (showMechanicalState) { show = true; *color = COLOR[MMODEL]; } + if (showMechanicalState) { show = true; *color = getDefaultColor(MMODEL); } else hide = true; } if (obj->toBaseMass()) { - if (showMass) { show = true; *color = COLOR[MASS]; } + if (showMass) { show = true; *color = getDefaultColor(MASS); } else hide = true; } if (obj->toTopology ()) { - if (showTopology) { show = true; *color = COLOR[TOPOLOGY]; } + if (showTopology) { show = true; *color = getDefaultColor(TOPOLOGY); } else hide = true; } if (obj->toCollisionModel()) { - if (showCollisionModel) { show = true; *color = COLOR[CMODEL]; } + if (showCollisionModel) { show = true; *color = getDefaultColor(CMODEL); } else hide = true; } if (obj->toBaseMapping()) { - if (showMapping) { show = true; *color = COLOR[MAPPING]; } + if (showMapping) { show = true; *color = getDefaultColor(MAPPING); } else hide = true; } if (obj->toContextObject()) { - if (showContext) { show = true; *color = COLOR[CONTEXT]; } + if (showContext) { show = true; *color = getDefaultColor(CONTEXT); } else hide = true; } if (obj->toPipeline() @@ -129,44 +127,44 @@ bool ExportDotVisitor::display(core::objectmodel::BaseObject* obj, const char ** || obj->toContactManager() || obj->toCollisionGroupManager()) { - if (showCollisionPipeline) { show = true; *color = COLOR[COLLISION]; } + if (showCollisionPipeline) { show = true; *color = getDefaultColor(COLLISION); } else hide = true; } if (obj->toOdeSolver()) { - if (showSolver) { show = true; *color = COLOR[SOLVER]; } + if (showSolver) { show = true; *color = getDefaultColor(SOLVER); } else hide = true; } if (obj->toBaseInteractionForceField() && obj->toBaseInteractionForceField()->getMechModel1()!=obj->toBaseInteractionForceField()->getMechModel2()) { - if (showInteractionForceField) { show = true; *color = COLOR[IFFIELD]; } + if (showInteractionForceField) { show = true; *color = getDefaultColor(IFFIELD); } else hide = true; } else if (obj->toBaseForceField()) { - if (showForceField) { show = true; *color = COLOR[FFIELD]; } + if (showForceField) { show = true; *color = getDefaultColor(FFIELD); } else hide = true; } if (obj->toBaseProjectiveConstraintSet()) { - if (showConstraint) { show = true; *color = COLOR[PROJECTIVECONSTRAINTSET]; } + if (showConstraint) { show = true; *color = getDefaultColor(PROJECTIVECONSTRAINTSET); } else hide = true; } if (obj->toBaseConstraintSet()) { - if (showConstraint) { show = true; *color = COLOR[CONSTRAINTSET]; } + if (showConstraint) { show = true; *color = getDefaultColor(CONSTRAINTSET); } else hide = true; } if (obj->toBehaviorModel()) { - if (showBehaviorModel) { show = true; *color = COLOR[BMODEL]; } + if (showBehaviorModel) { show = true; *color = getDefaultColor(BMODEL); } else hide = true; } if (obj->toVisualModel() && !hide && !show) { - if (showVisualModel) { show = true; *color = COLOR[VMODEL]; } + if (showVisualModel) { show = true; *color = getDefaultColor(VMODEL); } else hide = true; } From 8fd1818884227d8766cd8c81b81b9a8ea5f79c51 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Tue, 27 Feb 2024 11:23:26 +0100 Subject: [PATCH 2/4] Add prefab in runSofa. --- .../sofa/gui/qt/GraphListenerQListView.cpp | 10 ++++++- .../gui/qt/resources/icons/iconprefab.xpm | 26 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 Sofa/GUI/Qt/src/sofa/gui/qt/resources/icons/iconprefab.xpm diff --git a/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp b/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp index 8cea765d7a3..9b3640a4a5f 100644 --- a/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp +++ b/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp @@ -39,6 +39,7 @@ using sofa::simulation::Colors; #include "resources/icons/iconmultinode.xpm" #include "resources/icons/iconnode.xpm" +#include "resources/icons/iconprefab.xpm" #include "resources/icons/iconinfo.xpm" #include "resources/icons/iconwarning.xpm" #include "resources/icons/iconerror.xpm" @@ -88,7 +89,11 @@ QPixmap* getPixmapForFlags(unsigned int flags, std::map& { if(flags&(1<(iconnode_xpm); + const char** icon = nullptr; + if(flags & (1 << Colors::PREFAB)) + icon = reinterpret_cast(iconprefab_xpm); + else + icon = reinterpret_cast(iconnode_xpm); // Create a new image from pixmap const QImage timg(icon); @@ -213,6 +218,9 @@ QPixmap* getPixmapForFlagsAndState(unsigned int typeFlags, QPixmap* getBaseNodePixmap(core::objectmodel::BaseNode* node, bool haveInfo, bool haveWarning, bool haveErrors) { unsigned int flags = 1 << Colors::NODE; + if(node->getClassName() == "Prefab") + flags |= 1 << Colors::PREFAB; + return getPixmapForFlagsAndState(flags, node->getContext()->isSleeping(), haveInfo, haveWarning, haveErrors); diff --git a/Sofa/GUI/Qt/src/sofa/gui/qt/resources/icons/iconprefab.xpm b/Sofa/GUI/Qt/src/sofa/gui/qt/resources/icons/iconprefab.xpm new file mode 100644 index 00000000000..755fc84459a --- /dev/null +++ b/Sofa/GUI/Qt/src/sofa/gui/qt/resources/icons/iconprefab.xpm @@ -0,0 +1,26 @@ +/* XPM */ +const static char * iconprefab_xpm[] = { +"20 20 3 1", +" c None", +". c #000000", +"+ c #67578F", +" ", +" ", +" ", +" ...... ", +" .++++. ", +" .++++++. ", +" .++++++++. ", +" .++++++++++. ", +" .++++++++++. ", +".++++++++++++. ", +".++++++++++++. ", +".++++++++++++. ", +" .++++++++++. ", +" .++++++++++. ", +" .++++++++. ", +" .++++++. ", +" .++++. ", +" ...... ", +" ", +" "}; From 72d616995d5d46c8ab327c26808f357f1596e1b5 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Wed, 28 Feb 2024 14:30:02 +0100 Subject: [PATCH 3/4] Restore old Color.h file --- .../sofa/gui/qt/GraphListenerQListView.cpp | 17 +---- .../Core/src/sofa/simulation/Colors.h | 62 ++++++++----------- .../src/sofa/simulation/ExportDotVisitor.cpp | 34 +++++----- 3 files changed, 48 insertions(+), 65 deletions(-) diff --git a/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp b/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp index 9b3640a4a5f..f3024c28527 100644 --- a/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp +++ b/Sofa/GUI/Qt/src/sofa/gui/qt/GraphListenerQListView.cpp @@ -35,11 +35,10 @@ #include using sofa::component::sceneutility::InfoComponent ; -using sofa::simulation::Colors; +using namespace sofa::simulation; #include "resources/icons/iconmultinode.xpm" #include "resources/icons/iconnode.xpm" -#include "resources/icons/iconprefab.xpm" #include "resources/icons/iconinfo.xpm" #include "resources/icons/iconwarning.xpm" #include "resources/icons/iconerror.xpm" @@ -56,10 +55,6 @@ namespace sofa::gui::qt { //*********************************************************************************************************** -static const int iconWidth=8; -static const int iconHeight=16; -static const int iconMargin=6; - static int hexval(char c) { if (c>='0' && c<='9') return c-'0'; @@ -90,10 +85,7 @@ QPixmap* getPixmapForFlags(unsigned int flags, std::map& if(flags&(1<(iconprefab_xpm); - else - icon = reinterpret_cast(iconnode_xpm); + icon = reinterpret_cast(iconnode_xpm); // Create a new image from pixmap const QImage timg(icon); @@ -132,7 +124,7 @@ QPixmap* getPixmapForFlags(unsigned int flags, std::map& } } - const char* color = simulation::getDefaultColor(nc); + const char* color = Colors::COLOR[nc]; const int r = (hexval(color[1])*16+hexval(color[2])); const int g = (hexval(color[3])*16+hexval(color[4])); const int b = (hexval(color[5])*16+hexval(color[6])); @@ -218,9 +210,6 @@ QPixmap* getPixmapForFlagsAndState(unsigned int typeFlags, QPixmap* getBaseNodePixmap(core::objectmodel::BaseNode* node, bool haveInfo, bool haveWarning, bool haveErrors) { unsigned int flags = 1 << Colors::NODE; - if(node->getClassName() == "Prefab") - flags |= 1 << Colors::PREFAB; - return getPixmapForFlagsAndState(flags, node->getContext()->isSleeping(), haveInfo, haveWarning, haveErrors); diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.h b/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.h index 651a4c17956..f305ecd50bd 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.h +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/Colors.h @@ -26,13 +26,12 @@ #include -namespace sofa::simulation +namespace sofa::simulation::Colors { -typedef enum +enum { - NODE = 0, - PREFAB, + NODE, OBJECT, CONTEXT, BMODEL, @@ -52,15 +51,14 @@ typedef enum LOADER , CONFIGURATIONSETTING, ALLCOLORS -} Colors; +}; // See http://www.graphviz.org/doc/info/colors.html // The following is mostly the "set312" colors -static const char* DEFAULT_COLOR[ALLCOLORS]= +static const char* COLOR[ALLCOLORS]= { /*Node =*/ "#dedede", // color 9 - /*Prefab =*/ "#dedede", // color 9 /*Object =*/ "#ffffff", // white /*Context =*/ "#d7191c", // color spectral4/1 /*BehaviorModel =*/ "#93ff49", // color 7 (brighter) @@ -81,36 +79,30 @@ static const char* DEFAULT_COLOR[ALLCOLORS]= /*ConfigurationSetting =*/ "#aaaaaa", // pale pink }; -inline const char* getDefaultColor(unsigned int index, const char* defaultValue="") +inline const char* getColor(const char* classname) { - if(index >= Colors::ALLCOLORS) - return defaultValue; - return DEFAULT_COLOR[index]; -} + if (!strcmp(classname,"BaseNode")) return COLOR[NODE]; + if (!strcmp(classname,"BaseObject")) return COLOR[OBJECT]; + if (!strcmp(classname,"ContextObject")) return COLOR[CONTEXT]; + if (!strcmp(classname,"BehaviorModel")) return COLOR[BMODEL]; + if (!strcmp(classname,"CollisionModel")) return COLOR[CMODEL]; + if (!strcmp(classname,"MechanicalState")) return COLOR[MMODEL]; + if (!strcmp(classname,"ProjectiveConstraintSet")) return COLOR[PROJECTIVECONSTRAINTSET]; + if (!strcmp(classname,"ConstraintSet")) return COLOR[CONSTRAINTSET]; + if (!strcmp(classname,"InteractionForceField")) return COLOR[IFFIELD]; + if (!strcmp(classname,"ForceField")) return COLOR[FFIELD]; + if (!strcmp(classname,"BaseAnimationLoop")) return COLOR[SOLVER]; + if (!strcmp(classname,"OdeSolver")) return COLOR[SOLVER]; + if (!strcmp(classname,"CollisionPipeline")) return COLOR[COLLISION]; + if (!strcmp(classname,"MechanicalMapping")) return COLOR[MMAPPING]; + if (!strcmp(classname,"Mapping")) return COLOR[MAPPING]; + if (!strcmp(classname,"Mass")) return COLOR[MASS]; + if (!strcmp(classname,"Topology")) return COLOR[TOPOLOGY]; + if (!strcmp(classname,"VisualModel")) return COLOR[VMODEL]; + if (!strcmp(classname,"Loader")) return COLOR[LOADER]; + if (!strcmp(classname,"ConfigurationSetting")) return COLOR[CONFIGURATIONSETTING]; + return ""; -inline const char* getDefaultColor(const char* classname, const char* defaultValue="") -{ - if (!strcmp(classname,"BaseNode")) return DEFAULT_COLOR[NODE]; - if (!strcmp(classname,"BaseObject")) return DEFAULT_COLOR[OBJECT]; - if (!strcmp(classname,"ContextObject")) return DEFAULT_COLOR[CONTEXT]; - if (!strcmp(classname,"BehaviorModel")) return DEFAULT_COLOR[BMODEL]; - if (!strcmp(classname,"CollisionModel")) return DEFAULT_COLOR[CMODEL]; - if (!strcmp(classname,"MechanicalState")) return DEFAULT_COLOR[MMODEL]; - if (!strcmp(classname,"ProjectiveConstraintSet")) return DEFAULT_COLOR[PROJECTIVECONSTRAINTSET]; - if (!strcmp(classname,"ConstraintSet")) return DEFAULT_COLOR[CONSTRAINTSET]; - if (!strcmp(classname,"InteractionForceField")) return DEFAULT_COLOR[IFFIELD]; - if (!strcmp(classname,"ForceField")) return DEFAULT_COLOR[FFIELD]; - if (!strcmp(classname,"BaseAnimationLoop")) return DEFAULT_COLOR[SOLVER]; - if (!strcmp(classname,"OdeSolver")) return DEFAULT_COLOR[SOLVER]; - if (!strcmp(classname,"CollisionPipeline")) return DEFAULT_COLOR[COLLISION]; - if (!strcmp(classname,"MechanicalMapping")) return DEFAULT_COLOR[MMAPPING]; - if (!strcmp(classname,"Mapping")) return DEFAULT_COLOR[MAPPING]; - if (!strcmp(classname,"Mass")) return DEFAULT_COLOR[MASS]; - if (!strcmp(classname,"Topology")) return DEFAULT_COLOR[TOPOLOGY]; - if (!strcmp(classname,"VisualModel")) return DEFAULT_COLOR[VMODEL]; - if (!strcmp(classname,"Loader")) return DEFAULT_COLOR[LOADER]; - if (!strcmp(classname,"ConfigurationSetting")) return DEFAULT_COLOR[CONFIGURATIONSETTING]; - return defaultValue; } } diff --git a/Sofa/framework/Simulation/Core/src/sofa/simulation/ExportDotVisitor.cpp b/Sofa/framework/Simulation/Core/src/sofa/simulation/ExportDotVisitor.cpp index aa69ace2729..d967cea7992 100644 --- a/Sofa/framework/Simulation/Core/src/sofa/simulation/ExportDotVisitor.cpp +++ b/Sofa/framework/Simulation/Core/src/sofa/simulation/ExportDotVisitor.cpp @@ -71,10 +71,11 @@ ExportDotVisitor::~ExportDotVisitor() /// Test if a node should be displayed bool ExportDotVisitor::display(Node* node, const char **color) { + using namespace Colors; if (!node) return false; if (showNode) { - if (color) *color = getDefaultColor(NODE); + if (color) *color = COLOR[NODE]; return true; } else @@ -84,41 +85,42 @@ bool ExportDotVisitor::display(Node* node, const char **color) /// Test if an object should be displayed bool ExportDotVisitor::display(core::objectmodel::BaseObject* obj, const char **color) { + using namespace Colors; const char* c = nullptr; if (color==nullptr) color=&c; if (!obj) return false; if (!showObject) return false; - *color = getDefaultColor(OBJECT); + *color = COLOR[OBJECT]; bool show = false; bool hide = false; if (obj->toBaseMechanicalState()) { - if (showMechanicalState) { show = true; *color = getDefaultColor(MMODEL); } + if (showMechanicalState) { show = true; *color = COLOR[MMODEL]; } else hide = true; } if (obj->toBaseMass()) { - if (showMass) { show = true; *color = getDefaultColor(MASS); } + if (showMass) { show = true; *color = COLOR[MASS]; } else hide = true; } if (obj->toTopology ()) { - if (showTopology) { show = true; *color = getDefaultColor(TOPOLOGY); } + if (showTopology) { show = true; *color = COLOR[TOPOLOGY]; } else hide = true; } if (obj->toCollisionModel()) { - if (showCollisionModel) { show = true; *color = getDefaultColor(CMODEL); } + if (showCollisionModel) { show = true; *color = COLOR[CMODEL]; } else hide = true; } if (obj->toBaseMapping()) { - if (showMapping) { show = true; *color = getDefaultColor(MAPPING); } + if (showMapping) { show = true; *color = COLOR[MAPPING]; } else hide = true; } if (obj->toContextObject()) { - if (showContext) { show = true; *color = getDefaultColor(CONTEXT); } + if (showContext) { show = true; *color = COLOR[CONTEXT]; } else hide = true; } if (obj->toPipeline() @@ -127,44 +129,44 @@ bool ExportDotVisitor::display(core::objectmodel::BaseObject* obj, const char ** || obj->toContactManager() || obj->toCollisionGroupManager()) { - if (showCollisionPipeline) { show = true; *color = getDefaultColor(COLLISION); } + if (showCollisionPipeline) { show = true; *color = COLOR[COLLISION]; } else hide = true; } if (obj->toOdeSolver()) { - if (showSolver) { show = true; *color = getDefaultColor(SOLVER); } + if (showSolver) { show = true; *color = COLOR[SOLVER]; } else hide = true; } if (obj->toBaseInteractionForceField() && obj->toBaseInteractionForceField()->getMechModel1()!=obj->toBaseInteractionForceField()->getMechModel2()) { - if (showInteractionForceField) { show = true; *color = getDefaultColor(IFFIELD); } + if (showInteractionForceField) { show = true; *color = COLOR[IFFIELD]; } else hide = true; } else if (obj->toBaseForceField()) { - if (showForceField) { show = true; *color = getDefaultColor(FFIELD); } + if (showForceField) { show = true; *color = COLOR[FFIELD]; } else hide = true; } if (obj->toBaseProjectiveConstraintSet()) { - if (showConstraint) { show = true; *color = getDefaultColor(PROJECTIVECONSTRAINTSET); } + if (showConstraint) { show = true; *color = COLOR[PROJECTIVECONSTRAINTSET]; } else hide = true; } if (obj->toBaseConstraintSet()) { - if (showConstraint) { show = true; *color = getDefaultColor(CONSTRAINTSET); } + if (showConstraint) { show = true; *color = COLOR[CONSTRAINTSET]; } else hide = true; } if (obj->toBehaviorModel()) { - if (showBehaviorModel) { show = true; *color = getDefaultColor(BMODEL); } + if (showBehaviorModel) { show = true; *color = COLOR[BMODEL]; } else hide = true; } if (obj->toVisualModel() && !hide && !show) { - if (showVisualModel) { show = true; *color = getDefaultColor(VMODEL); } + if (showVisualModel) { show = true; *color = COLOR[VMODEL]; } else hide = true; } From 3558bf484f4f13f534ec28e8646a3514f619cfc9 Mon Sep 17 00:00:00 2001 From: Damien Marchal Date: Wed, 28 Feb 2024 14:30:51 +0100 Subject: [PATCH 4/4] Remove prefab icon --- .../gui/qt/resources/icons/iconprefab.xpm | 26 ------------------- 1 file changed, 26 deletions(-) delete mode 100644 Sofa/GUI/Qt/src/sofa/gui/qt/resources/icons/iconprefab.xpm diff --git a/Sofa/GUI/Qt/src/sofa/gui/qt/resources/icons/iconprefab.xpm b/Sofa/GUI/Qt/src/sofa/gui/qt/resources/icons/iconprefab.xpm deleted file mode 100644 index 755fc84459a..00000000000 --- a/Sofa/GUI/Qt/src/sofa/gui/qt/resources/icons/iconprefab.xpm +++ /dev/null @@ -1,26 +0,0 @@ -/* XPM */ -const static char * iconprefab_xpm[] = { -"20 20 3 1", -" c None", -". c #000000", -"+ c #67578F", -" ", -" ", -" ", -" ...... ", -" .++++. ", -" .++++++. ", -" .++++++++. ", -" .++++++++++. ", -" .++++++++++. ", -".++++++++++++. ", -".++++++++++++. ", -".++++++++++++. ", -" .++++++++++. ", -" .++++++++++. ", -" .++++++++. ", -" .++++++. ", -" .++++. ", -" ...... ", -" ", -" "};