From: asozinov Date: Wed, 24 May 2023 15:24:43 +0000 (+0100) Subject: small improves X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b4d6aa45f98df09b3b3b46b66237a85198e24eb2;p=modules%2Fshaper.git small improves --- diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index d4cefa983..038b757ee 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -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 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 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) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp index 714625517..fa31f92cb 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp @@ -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 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 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 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(); } diff --git a/src/Model/Model_ResultBody.cpp b/src/Model/Model_ResultBody.cpp index 3475b4251..82f644ae3 100644 --- a/src/Model/Model_ResultBody.cpp +++ b/src/Model/Model_ResultBody.cpp @@ -317,7 +317,11 @@ std::wstring Model_ResultBody::addShapeName(std::shared_ptr 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& 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(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(new TopoDS_Shape(aFace)); + std::wstring aName = findShapeName(aGeomFace); + /// + for (std::map< std::wstring, std::shared_ptr >::iterator it = + myNamesShape.begin(); + it != myNamesShape.end(); + ++it) + { + TopoDS_Shape curSelectedShape = (*it).second->impl(); + 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 &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()); diff --git a/src/XGUI/XGUI_ColorDialog.cpp b/src/XGUI/XGUI_ColorDialog.cpp index 184b56c68..a915292ee 100644 --- a/src/XGUI/XGUI_ColorDialog.cpp +++ b/src/XGUI/XGUI_ColorDialog.cpp @@ -25,6 +25,7 @@ #include #include +#include #include #include #include @@ -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& theValue) { if (theValue.size() != 3) diff --git a/src/XGUI/XGUI_ColorDialog.h b/src/XGUI/XGUI_ColorDialog.h index 2bd94e2a7..bc4e2f722 100644 --- a/src/XGUI/XGUI_ColorDialog.h +++ b/src/XGUI/XGUI_ColorDialog.h @@ -25,6 +25,7 @@ #include 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& 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 diff --git a/src/XGUI/XGUI_Workshop.cpp b/src/XGUI/XGUI_Workshop.cpp index fea75fbf8..3d128ef70 100644 --- a/src/XGUI/XGUI_Workshop.cpp +++ b/src/XGUI/XGUI_Workshop.cpp @@ -2625,6 +2625,7 @@ void XGUI_Workshop::changeColor(const QMap>& 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>& theS ResultBodyPtr aBodyResult = std::dynamic_pointer_cast(aResult); foreach(GeomShapePtr aShape, theSelectedObjects[aResult]) { - if (aResult->shape()->impl().IsEqual(aShape->impl()) || !isColorOnSubShape) + if (aResult->shape()->impl().IsEqual(aShape->impl()) || !isColorOnSubShape || !isSetToShape) { if (aResult.get() != NULL) {