Salome HOME
Issue #2468 : Crash when sketching circles successively on a repetition.
[modules/shaper.git] / src / PartSet / PartSet_IconFactory.cpp
index 30fe5aa4b718a655791f955bfa6e2d6cd2db9f76..42b3d4d62f6f65b516232f300dbc7f603d3ba098 100644 (file)
@@ -1,8 +1,22 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File:        PartSet_IconFactory.cpp
-// Created:     28 Jul 2015
-// Author:      Vitaly SMETANNIKOV
+// Copyright (C) 2014-2017  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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// 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
+//
+// See http://www.salome-platform.org/ or
+// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+//
 
 #include "PartSet_IconFactory.h"
 #include <ModuleBase_ActionInfo.h>
 #include <Config_FeatureMessage.h>
 #include <Events_Loop.h>
 
+#include <CollectionPlugin_Group.h>
+
 QMap<QString, QString> PartSet_IconFactory::myIcons;
 
 PartSet_IconFactory::PartSet_IconFactory():ModuleBase_IconFactory()
 {
-  setFactory(this);
-  Events_Loop::loop()->registerListener(this, 
+  Events_Loop::loop()->registerListener(this,
     Events_Loop::eventByName(Config_FeatureMessage::GUI_EVENT()));
 }
 
@@ -29,6 +44,9 @@ QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
 {
   QIcon anIcon;
 
+  if (!theObj.get())
+    return anIcon;
+
   FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
   if (aFeature.get()) {
     std::string aKind = aFeature->getKind();
@@ -42,7 +60,7 @@ QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
     switch(aState) {
       case ModelAPI_StateDone:
       case ModelAPI_StateNothing: {
-        anIcon = QIcon(anIconString);
+        anIcon = loadIcon(anIconString);
       }
       break;
       case ModelAPI_StateMustBeUpdated: {
@@ -58,24 +76,61 @@ QIcon PartSet_IconFactory::getIcon(ObjectPtr theObj)
                                              anIconString);
       }
       break;
-      default: break;  
+      default: break;
     }
-  } else {
-    std::string aGroup = theObj->groupName();
-    if (aGroup == ModelAPI_ResultPart::group()) {
-      return QIcon(":pictures/part_ico.png");
-    } else {
-      if (theObj && theObj->data() && theObj->data()->execState() == ModelAPI_StateMustBeUpdated)
-        return QIcon(":pictures/constr_object_modified.png");
-      return QIcon(":pictures/constr_object.png");
+  }
+
+  if (theObj->data() && theObj->data()->execState() == ModelAPI_StateMustBeUpdated)
+    return QIcon(":pictures/constr_object_modified.png");
+
+  std::string aGroup = theObj->groupName();
+  if (aGroup == ModelAPI_ResultPart::group())
+    return QIcon(":pictures/part_ico.png");
+
+  if (aGroup == ModelAPI_ResultConstruction::group())
+    return QIcon(":pictures/constr_object.png");
+
+  ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObj);
+  if (aResult.get()) {
+    GeomShapePtr aShape = aResult->shape();
+    if(aShape.get()) {
+      switch(aShape->shapeType()) {
+        case GeomAPI_Shape::COMPOUND: {
+          FeaturePtr aFeature = ModelAPI_Feature::feature(theObj);
+          if (aFeature.get() && aFeature->getKind() == CollectionPlugin_Group::ID()) {
+            switch (aShape->typeOfCompoundShapes()) {
+            case GeomAPI_Shape::VERTEX:
+              return QIcon(":icons/group_vertex.png");
+            case GeomAPI_Shape::EDGE:
+              return QIcon(":icons/group_edge.png");
+            case GeomAPI_Shape::FACE:
+              return QIcon(":icons/group_face.png");
+            case GeomAPI_Shape::SOLID:
+              return QIcon(":icons/group_solid.png");
+            }
+          }
+          ResultBodyPtr aBody = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
+          if (aBody.get() && aBody->isConnectedTopology())
+            return QIcon(":pictures/compoundofsolids.png");
+          return QIcon(":pictures/compound.png");
+        }
+        case GeomAPI_Shape::COMPSOLID: return QIcon(":pictures/compsolid.png");
+        case GeomAPI_Shape::SOLID:     return QIcon(":pictures/solid.png");
+        case GeomAPI_Shape::SHELL:     return QIcon(":pictures/shell.png");
+        case GeomAPI_Shape::FACE:      return QIcon(":pictures/face.png");
+        case GeomAPI_Shape::WIRE:      return QIcon(":pictures/wire.png");
+        case GeomAPI_Shape::EDGE:      return QIcon(":pictures/edge.png");
+        case GeomAPI_Shape::VERTEX:    return QIcon(":pictures/vertex.png");
+      }
     }
   }
-  return anIcon;  
+  return anIcon;
 }
 
 void PartSet_IconFactory::processEvent(const std::shared_ptr<Events_Message>& theMessage)
 {
-  if (theMessage->eventID() == Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
+  if (theMessage->eventID() ==
+      Events_Loop::loop()->eventByName(Config_FeatureMessage::GUI_EVENT())) {
     std::shared_ptr<Config_FeatureMessage> aFeatureMsg =
        std::dynamic_pointer_cast<Config_FeatureMessage>(theMessage);
     if (!aFeatureMsg->isInternal()) {