]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
small improves color_on_sub_shape
authorasozinov <alexey.sozinov@opencascade.com>
Wed, 24 May 2023 15:24:43 +0000 (16:24 +0100)
committerasozinov <alexey.sozinov@opencascade.com>
Fri, 1 Mar 2024 13:52:53 +0000 (13:52 +0000)
src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp
src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp
src/Model/Model_ResultBody.cpp
src/XGUI/XGUI_ColorDialog.cpp
src/XGUI/XGUI_ColorDialog.h
src/XGUI/XGUI_Workshop.cpp

index d4cefa983b3159d5454cc85448f0a80167ca06c6..038b757ee9d27d1338e04fea0950d8acff1efa89 100644 (file)
@@ -256,7 +256,7 @@ void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
     aResult = IGESExport(theFileName, aFormatName, aShape, anError);
   } else if (aFormatName == "STEP")
   {
-    //aResult = STEPExport(theFileName, aFormatName, aShape, anError);
+    aResult = STEPExport(theFileName, aShapes, aContexts, anError);
   } else {
     anError = "Unsupported format: " + aFormatName;
   }
@@ -642,7 +642,7 @@ void ExchangePlugin_ExportFeature::exportSTEP(const std::string & theFileName)
        aCurShape = anAttrSelection->context()->shape();
     if (!aCurShape.get())
        continue;
-    #ifndef HAVE_SALOME
+    //#ifndef HAVE_SALOME
     ResultPtr aRes = anAttrSelection->context();
     std::vector<int> aColor;
     ModelAPI_Tools::getColor(aRes, aColor);
@@ -651,7 +651,7 @@ void ExchangePlugin_ExportFeature::exportSTEP(const std::string & theFileName)
     {
       aColoredShapes[aCurShape] = aColor;
     }
-    #endif
+    //#endif
       aShapeList.push_back(aCurShape);
     }
   std::shared_ptr<GeomAPI_Shape> aShape =
@@ -659,7 +659,7 @@ void ExchangePlugin_ExportFeature::exportSTEP(const std::string & theFileName)
   #ifndef HAVE_SALOME
     bool aRes = true;// STEPExport(theFileName, aShape, aColoredShapes, anError);
   #else
-    bool aRes = true;// STEPExport(theFileName, "STEP", aShape, anError);
+    bool aRes = STEPExport(theFileName, aShape, aColoredShapes, anError);
   #endif
 
   if (!anError.empty() || !aRes)
index 714625517a03413700e336c709401c2fd13985f7..fa31f92cba2e29fc3d984571e168bcfca47a1876 100644 (file)
@@ -316,6 +316,7 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
           theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorSurf, aCol) ||
           theColorTool->GetColor(aXp2.Current(), XCAFDoc_ColorCurv, aCol)) {
           double aR = aCol.Red(), aG = aCol.Green(), aB = aCol.Blue();
+#if 0
           TopoDS_Face aFace = TopoDS::Face(aXp2.Current());
           std::vector<int> aColRGB = {int(aR*255),int(aG*255),int(aB*255)};
           std::wstringstream aNameFace;
@@ -324,8 +325,20 @@ void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &theShapeTool,
                   aShapeface.Move(theLoc);
           }
           aShapeGeom->setImpl(new TopoDS_Shape(aShapeface));
-          theResultBody->addShapeColor(
-          theResultBody->addShapeName(aShapeGeom , aNameFace.str()), aColRGB);
+          theResultBody->addShapeColor(theResultBody->addShapeName(aFaceGeom, aNameFace), aColRGB);
+#else
+                    //TopoDS_Face aFace = TopoDS::Face(aXp2.Current());
+          std::vector<int> aColRGB = { int(aR * 255),int(aG * 255),int(aB * 255) };
+          std::wstring aNameFace;
+          TopoDS_Shape aShapeface = aXp2.Current();
+          if (!theLoc.IsIdentity()) {
+            aShapeface.Move(theLoc);
+          }
+          std::shared_ptr<GeomAPI_Shape> aFaceGeom(new GeomAPI_Shape);
+          aFaceGeom->setImpl(new TopoDS_Shape(aShapeface));
+          theResultBody->addShapeColor(theResultBody->addShapeName(aFaceGeom, aNameFace), aColRGB);
+#endif
+          //std::cout << "Subshape " << Locale::Convert::toString(L"XXX") << " " << aColRGB[0] << aColRGB[1] << aColRGB[2] << std::endl;
         }
         aXp2.Next();
       }
index 3475b42512ce6070dd509629b136845a77e7fdc9..82f644ae3b99fc38c07144109cfb608905dceb5f 100644 (file)
@@ -317,7 +317,11 @@ std::wstring Model_ResultBody::addShapeName(std::shared_ptr<GeomAPI_Shape> thesh
   int indice = 1;
   std::wstringstream aName;
   aName << theName;
-  while(myNamesShape.find(aName.str()) != myNamesShape.end() ){
+#if 0
+  while (myNamesShape.find(aName.str()) != myNamesShape.end()) {
+#else
+  while (aName.str().empty() || myNamesShape.find(aName.str()) != myNamesShape.end()) {
+#endif
     aName.str(L"");
     aName << theName << L"__" << indice;
     indice++;
@@ -455,6 +459,45 @@ void Model_ResultBody::updateSubs(const std::shared_ptr<GeomAPI_Shape>& theThisS
       aECreator->sendUpdated(data()->owner(), EVENT_DISP);
     }
     cleanCash();
+  }
+  else if (!aThisShape.IsNull() && (aThisShape.ShapeType() == TopAbs_SOLID ||
+           aThisShape.ShapeType() == TopAbs_SHELL)) {
+    std::cout << ".....subshape is a SOLID or SHELL" << std::endl;
+    // Iterate on all faces
+    //MBS:
+    ResultBodyPtr anOwner = std::dynamic_pointer_cast<ModelAPI_ResultBody>(data()->owner());
+    TopExp_Explorer aExp(aThisShape, TopAbs_FACE);
+    for (; aExp.More(); aExp.Next()) {
+      TopoDS_Shape aFace = aExp.Current();
+      if (!aFace.IsNull()) {
+        GeomShapePtr aGeomFace(new GeomAPI_Shape);
+        aGeomFace->setImpl<TopoDS_Shape>(new TopoDS_Shape(aFace));
+        std::wstring aName = findShapeName(aGeomFace);
+        ///
+        for (std::map< std::wstring, std::shared_ptr<GeomAPI_Shape> >::iterator it =
+          myNamesShape.begin();
+          it != myNamesShape.end();
+          ++it)
+        {
+          TopoDS_Shape curSelectedShape = (*it).second->impl<TopoDS_Shape>();
+          if (curSelectedShape.TShape().IsNull())
+            continue;
+          if (aFace.TShape() == curSelectedShape.TShape())
+          {
+            aName = (*it).first; // Find necessary shape,
+                                 // but it NOT correct because result shape contains anothet location. WHY?
+            break;
+          }
+        }
+        ///
+        if (!aName.empty()) {
+          const std::vector<int> &aColor = findShapeColor(aName);
+          if (!aColor.empty()) {
+            ModelAPI_Tools::setColor(anOwner, aGeomFace, aColor);
+          }
+        }
+      }
+    }
   } else if (!mySubs.empty()) { // erase all subs
     while(!mySubs.empty()) {
       ResultBodyPtr anErased = *(mySubs.rbegin());
index 184b56c68fc86c4cc9957a8f86598f7f90dd6187..a915292eee1b33d29f144639bc6b76a5ebfef814 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <QLabel>
 #include <QButtonGroup>
+#include <QCheckBox>
 #include <QGridLayout>
 #include <QRadioButton>
 #include <QDialogButtonBox>
@@ -65,7 +66,7 @@ namespace
   };
 }
 
-XGUI_ColorDialog::XGUI_ColorDialog(QWidget* theParent)
+XGUI_ColorDialog::XGUI_ColorDialog(QWidget* theParent, bool theCheckBoxNeed)
   : QDialog(theParent, Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint)
 {
   setWindowTitle(tr("Color"));
@@ -84,16 +85,20 @@ XGUI_ColorDialog::XGUI_ColorDialog(QWidget* theParent)
   myButtonGroup->addButton(aColorChoiceBtn, 0);
   myButtonGroup->addButton(aRandomChoiceBtn, 1);
 
+  if (theCheckBoxNeed)
+    myTargetSetCheck = new QCheckBox(tr("Set on selected face"), this);
+
   aLay->addWidget(aColorChoiceBtn, 0, 0);
   aLay->addWidget(myColorButton, 0, 1);
   aLay->addWidget(aRandomChoiceBtn, 1, 0);
   aLay->addWidget(aRandomLabel, 1, 1);
+  aLay->addWidget(myTargetSetCheck, 2, 0, 1, 2);
 
   QDialogButtonBox* aButtons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel,
                                                     Qt::Horizontal, this);
   connect(aButtons, SIGNAL(accepted()), this, SLOT(accept()));
   connect(aButtons, SIGNAL(rejected()), this, SLOT(reject()));
-  aLay->addWidget(aButtons, 2, 0, 1, 2);
+  aLay->addWidget(aButtons, 3, 0, 1, 2);
 }
 
 bool XGUI_ColorDialog::isRandomColor() const
@@ -101,6 +106,11 @@ bool XGUI_ColorDialog::isRandomColor() const
   return myButtonGroup->checkedId() == 1;
 }
 
+bool XGUI_ColorDialog::isSetOnSubShape() const
+{
+  return myTargetSetCheck && myTargetSetCheck->isChecked();
+}
+
 void XGUI_ColorDialog::setColor(const std::vector<int>& theValue)
 {
   if (theValue.size() != 3)
index 2bd94e2a7136e3b90f28aa69fd3d2bc333702a6b..bc4e2f72204dd5ed8700e396591f37ee7d37614d 100644 (file)
@@ -25,6 +25,7 @@
 #include <QDialog>
 
 class QButtonGroup;
+class QCheckBox;
 class QtxColorButton;
 
 /**
@@ -39,7 +40,7 @@ class XGUI_ColorDialog : public QDialog
 public:
   /// Constructor
   /// \param theParent a parent widget for the dialog
-  XGUI_EXPORT XGUI_ColorDialog(QWidget* theParent);
+  XGUI_EXPORT XGUI_ColorDialog(QWidget* theParent, bool theCheckBoxNeed = true);
 
   XGUI_EXPORT virtual ~XGUI_ColorDialog() {};
 
@@ -47,6 +48,10 @@ public:
   /// \return a boolean value
   bool isRandomColor() const;
 
+  /// Returns whether the need set color on subshape only
+  /// \return a boolean value
+  bool isSetOnSubShape() const;
+
   /// Initializes the dialog with the given value. Set choice on certain value and fill it by.
   /// \param theValue an RGB components value
   void setColor(const std::vector<int>& theValue);
@@ -67,6 +72,7 @@ public:
 private:
   QButtonGroup* myButtonGroup; /// a group, contained random and certain color radio button choice
   QtxColorButton* myColorButton; /// a control to select a color
+  QCheckBox* myTargetSetCheck; /// a target shape for assign
 };
 
 #endif
index fea75fbf88d0ae4e1259b71668c9a86fb0a149c3..3d128ef705d71bb6b258d006a69a78f404a00e54 100644 (file)
@@ -2625,6 +2625,7 @@ void XGUI_Workshop::changeColor(const QMap<ResultPtr, QList<GeomShapePtr>>& theS
     return;
 
   bool isRandomColor = aDlg->isRandomColor();
+  bool isSetToShape = aDlg->isSetOnSubShape();
 
   // 3. abort the previous operation and start a new one
   SessionPtr aMgr = ModelAPI_Session::get();
@@ -2641,7 +2642,7 @@ void XGUI_Workshop::changeColor(const QMap<ResultPtr, QList<GeomShapePtr>>& theS
     ResultBodyPtr aBodyResult = std::dynamic_pointer_cast<ModelAPI_ResultBody>(aResult);
     foreach(GeomShapePtr aShape, theSelectedObjects[aResult])
     {
-      if (aResult->shape()->impl<TopoDS_Shape>().IsEqual(aShape->impl<TopoDS_Shape>()) || !isColorOnSubShape)
+      if (aResult->shape()->impl<TopoDS_Shape>().IsEqual(aShape->impl<TopoDS_Shape>()) || !isColorOnSubShape || !isSetToShape)
       {
         if (aResult.get() != NULL)
         {