From 14ff1067ec3e7aeb6e8a40ad0a61d59917d1fe2b Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me?= Date: Sat, 21 Nov 2020 18:05:59 +0100 Subject: [PATCH] Clean code --- src/BuildAPI/BuildAPI_Interpolation.cpp | 25 +- src/BuildPlugin/BuildPlugin_Interpolation.cpp | 31 +- src/BuildPlugin/BuildPlugin_Interpolation.h | 5 +- src/BuildPlugin/BuildPlugin_Plugin.cpp | 3 - src/BuildPlugin/BuildPlugin_Validators.cpp | 2 +- src/BuildPlugin/Test/TestInterpolation.py | 6 +- src/BuildPlugin/interpolation_widget.xml | 1 - .../FeaturesPlugin_WidgetCreator.cpp | 56 -- .../FeaturesPlugin_WidgetCreator.h | 64 -- ...aturesPlugin_WidgetFilletMultiRadiuses.cpp | 720 ------------------ ...FeaturesPlugin_WidgetFilletMultiRadiuses.h | 167 ---- .../GeomAlgoAPI_STEPImportXCAF.cpp | 446 ----------- src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h | 74 -- .../InitializationPlugin_EvalListener.cpp | 31 +- src/ModelAPI/ModelAPI_Events.h | 12 +- 15 files changed, 55 insertions(+), 1588 deletions(-) delete mode 100644 src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.cpp delete mode 100644 src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.h delete mode 100644 src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp delete mode 100644 src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.h delete mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp delete mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h diff --git a/src/BuildAPI/BuildAPI_Interpolation.cpp b/src/BuildAPI/BuildAPI_Interpolation.cpp index 353eff358..f651255be 100644 --- a/src/BuildAPI/BuildAPI_Interpolation.cpp +++ b/src/BuildAPI/BuildAPI_Interpolation.cpp @@ -31,14 +31,14 @@ BuildAPI_Interpolation::BuildAPI_Interpolation(const std::shared_ptr& theBaseObjects, - const ModelHighAPI_Selection& theStartTangent, - const ModelHighAPI_Selection& theEndTangent, - const bool theIsClosed, - const bool theIsToReorder) + const std::list& theBaseObjects, + const ModelHighAPI_Selection& theStartTangent, + const ModelHighAPI_Selection& theEndTangent, + const bool theIsClosed, + const bool theIsToReorder) : ModelHighAPI_Interface(theFeature) { - if(initialize()) { + if (initialize()) { fillAttribute(BuildPlugin_Interpolation::CREATION_METHOD_BY_SELECTION_ID(),mycreationmethod); setUseTangents(true); setTangents(theStartTangent, theEndTangent); @@ -49,11 +49,10 @@ BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature, } //================================================================================================== -BuildAPI_Interpolation::BuildAPI_Interpolation( - const FeaturePtr& theFeature, - const std::list& theBaseObjects, - const bool theIsClosed, - const bool theIsToReorder) +BuildAPI_Interpolation::BuildAPI_Interpolation(const FeaturePtr& theFeature, + const std::list& theBaseObjects, + const bool theIsClosed, + const bool theIsToReorder) : ModelHighAPI_Interface(theFeature) { if (initialize()) { @@ -137,7 +136,7 @@ void BuildAPI_Interpolation::dump(ModelHighAPI_Dumper& theDumper) const FeaturePtr aBase = feature(); std::string aPartName = theDumper.name(aBase->document()); - if( aBase->string(BuildPlugin_Interpolation::CREATION_METHOD_ID())->value() == + if (aBase->string(BuildPlugin_Interpolation::CREATION_METHOD_ID())->value() == BuildPlugin_Interpolation::CREATION_METHOD_BY_SELECTION_ID() ) { AttributeSelectionListPtr anAttrBaseObjects = @@ -158,7 +157,7 @@ void BuildAPI_Interpolation::dump(ModelHighAPI_Dumper& theDumper) const } theDumper << closed() << ", " << reorder() << ")" << std::endl; - }else{ + } else { theDumper << aBase << " = model.addInterpolation(" << aPartName ; AttributeStringPtr XtAttr = xt(); diff --git a/src/BuildPlugin/BuildPlugin_Interpolation.cpp b/src/BuildPlugin/BuildPlugin_Interpolation.cpp index 59e91ca81..2397c8331 100644 --- a/src/BuildPlugin/BuildPlugin_Interpolation.cpp +++ b/src/BuildPlugin/BuildPlugin_Interpolation.cpp @@ -31,7 +31,6 @@ #include #include -#include #include #include @@ -46,13 +45,7 @@ #include #include #include -#include - -#include - #include - -#include #include @@ -98,7 +91,7 @@ void BuildPlugin_Interpolation::initAttributes() data()->reflist(ARGUMENTS_ID())->setIsArgument(false); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ARGUMENTS_ID()); - if( string( XT_ID())->value() == "" + if ( string( XT_ID())->value() == "" && string( YT_ID())->value() == "" && string( ZT_ID())->value() == "") { @@ -112,9 +105,10 @@ void BuildPlugin_Interpolation::initAttributes() } } +//================================================================================================= void BuildPlugin_Interpolation::attributeChanged(const std::string& theID) { - if( (theID == XT_ID() + if ((theID == XT_ID() || theID == YT_ID() || theID == ZT_ID() || theID == MINT_ID() @@ -128,6 +122,7 @@ void BuildPlugin_Interpolation::attributeChanged(const std::string& theID) } } +//================================================================================================= void BuildPlugin_Interpolation::updateCoordinates() { std::wstring exp; @@ -135,7 +130,7 @@ void BuildPlugin_Interpolation::updateCoordinates() double aMaxt = real(MAXT_ID())->value(); int aNbrStep = integer(NUMSTEP_ID())->value(); - if ( aMaxt < aMint ) { + if (aMaxt < aMint) { setError("The minimum value of the parameter must be less than maximum value !!!" ); } @@ -143,7 +138,7 @@ void BuildPlugin_Interpolation::updateCoordinates() string(VARIABLE_ID())->setValue("t"); tables(VALUE_ID())->setSize(aNbrStep+1,4); - for( int step = 0; step <= aNbrStep; step++ ){ + for (int step = 0; step <= aNbrStep; step++ ){ ModelAPI_AttributeTables::Value aVal; aVal.myDouble = step * aScale + aMint; tables(VALUE_ID())->setValue(aVal,step,0); @@ -183,7 +178,7 @@ static GeomDirPtr selectionToDir(const AttributeSelectionPtr& theSelection) //================================================================================================= void BuildPlugin_Interpolation::execute() { - if( string(CREATION_METHOD_ID())->value() == CREATION_METHOD_BY_SELECTION_ID() ) + if (string(CREATION_METHOD_ID())->value() == CREATION_METHOD_BY_SELECTION_ID()) { // Get closed flag value bool isClosed = boolean(CLOSED_ID())->value(); @@ -244,9 +239,8 @@ void BuildPlugin_Interpolation::execute() setResult(aResultBody); - }else - { - if( string( XT_ID())->value() == "" + } else { + if (string( XT_ID())->value() == "" ||string( YT_ID())->value() == "" ||string( ZT_ID())->value() == "" ||tables(VALUE_ID())->rows()== 0 ) @@ -258,7 +252,7 @@ void BuildPlugin_Interpolation::execute() AttributeTablesPtr aTable = tables( VALUE_ID() ); std::list > aCoordPoints; - for( int step = 0; step < aTable->rows() ; step++ ){ + for (int step = 0; step < aTable->rows(); step++){ std::vector aCoordPoint; ModelAPI_AttributeTables::Value value; //x @@ -278,7 +272,7 @@ void BuildPlugin_Interpolation::execute() std::list aVertices; std::list >::const_iterator anItCoordPoints = aCoordPoints.begin(); - for( ; anItCoordPoints != aCoordPoints.end(); ++anItCoordPoints ){ + for (; anItCoordPoints != aCoordPoints.end(); ++anItCoordPoints){ GeomVertexPtr aVertex = GeomAlgoAPI_PointBuilder::vertex( (*anItCoordPoints)[0], @@ -309,7 +303,8 @@ void BuildPlugin_Interpolation::execute() } } -void BuildPlugin_Interpolation::evaluate(std::string& theError) +//================================================================================================= +void BuildPlugin_Interpolation::evaluate(std::string& theError) { FeaturePtr aMyPtr = std::dynamic_pointer_cast(data()->owner()); std::shared_ptr aProcessMessage = diff --git a/src/BuildPlugin/BuildPlugin_Interpolation.h b/src/BuildPlugin/BuildPlugin_Interpolation.h index 6697162bb..1eaa6116d 100644 --- a/src/BuildPlugin/BuildPlugin_Interpolation.h +++ b/src/BuildPlugin/BuildPlugin_Interpolation.h @@ -186,15 +186,18 @@ public: /// Creates a new part document if needed. BUILDPLUGIN_EXPORT virtual void execute(); + /// Called on change of any argument-attribute of this object. + /// \param[in] theID identifier of changed attribute. BUILDPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID); protected: /// Evaluates the expression x(t), y(t),z(t) in value table. void evaluate(std::string& theError); - //Update coordinates x,y,z + ///Update coordinates x,y,z void updateCoordinates(); + ///Output error for python interpreter std::string outErrorMessage; }; diff --git a/src/BuildPlugin/BuildPlugin_Plugin.cpp b/src/BuildPlugin/BuildPlugin_Plugin.cpp index 6614d0684..8cfc1132f 100644 --- a/src/BuildPlugin/BuildPlugin_Plugin.cpp +++ b/src/BuildPlugin/BuildPlugin_Plugin.cpp @@ -36,9 +36,6 @@ #include #include - - - // the only created instance of this plugin static BuildPlugin_Plugin* MY_INSTANCE = new BuildPlugin_Plugin(); diff --git a/src/BuildPlugin/BuildPlugin_Validators.cpp b/src/BuildPlugin/BuildPlugin_Validators.cpp index be26b1196..f0657537d 100644 --- a/src/BuildPlugin/BuildPlugin_Validators.cpp +++ b/src/BuildPlugin/BuildPlugin_Validators.cpp @@ -573,7 +573,7 @@ bool BuildPlugin_ValidatorBaseForVertex::isValid(const AttributePtr& theAttribut return true; } - +//================================================================================================= bool BuildPlugin_ValidatorExpressionInterpolation::isValid(const AttributePtr& theAttribute, const std::list& /*theArguments*/, Events_InfoMessage& theError) const diff --git a/src/BuildPlugin/Test/TestInterpolation.py b/src/BuildPlugin/Test/TestInterpolation.py index a06488579..d2460699f 100644 --- a/src/BuildPlugin/Test/TestInterpolation.py +++ b/src/BuildPlugin/Test/TestInterpolation.py @@ -178,9 +178,9 @@ Part_5 = model.addPart(partSet) Part_5_doc = Part_5.document() Interpolation_11 = model.addInterpolation(Part_5_doc, "sin(t)","cos(t)","t", 0, 100, 10) - -model.checkResult(Interpolation_11, model, 1, [0], [0], [0], [1], [2]) - +model.do() +model.testNbResults(Interpolation_11, 1) +model.end() # ============================================================================= # Test 13. Check Python dump # ============================================================================= diff --git a/src/BuildPlugin/interpolation_widget.xml b/src/BuildPlugin/interpolation_widget.xml index 21ccd2c84..b5036905f 100644 --- a/src/BuildPlugin/interpolation_widget.xml +++ b/src/BuildPlugin/interpolation_widget.xml @@ -36,7 +36,6 @@ diff --git a/src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.cpp b/src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.cpp deleted file mode 100644 index 05478d8bc..000000000 --- a/src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.cpp +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2014-2020 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 -// - -#include "FeaturesPlugin_WidgetCreator.h" -#include "FeaturesPlugin_WidgetFilletMultiRadiuses.h" - - -FeaturesPlugin_WidgetCreator::FeaturesPlugin_WidgetCreator() -: ModuleBase_IWidgetCreator() -{ - myPanelTypes.insert("multiradius-panel"); - myPanelTypes.insert("multiradiuscurv-panel"); -} - -void FeaturesPlugin_WidgetCreator::widgetTypes(std::set& theTypes) -{ - theTypes = myPanelTypes; -} - - -ModuleBase_ModelWidget* FeaturesPlugin_WidgetCreator::createWidgetByType( - const std::string& theType, - QWidget* theParent, - Config_WidgetAPI* theWidgetApi, - ModuleBase_IWorkshop* theWorkshop) -{ - ModuleBase_ModelWidget* aWidget = 0; - if (myPanelTypes.find(theType) == myPanelTypes.end()) - return aWidget; - - if (theType == "multiradius-panel") { - aWidget = new FeaturesPlugin_WidgetFilletMultiRadiuses(theParent, theWorkshop, theWidgetApi, true); - }else if (theType == "multiradiuscurv-panel") - { - aWidget = new FeaturesPlugin_WidgetFilletMultiRadiuses(theParent, theWorkshop, theWidgetApi, false); - } - - - return aWidget; -} diff --git a/src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.h b/src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.h deleted file mode 100644 index 98ba3b63e..000000000 --- a/src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (C) 2014-2020 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 -// - -#ifndef FeaturesPlugin_WidgetCreator_H -#define FeaturesPlugin_WidgetCreator_H - - -#include "FeaturesPlugin.h" -#include - -#include -#include - -class QWidget; - -/** -* \ingroup GUI -* Interface to WidgetCreator which can create specific widgets by type -*/ -class FeaturesPlugin_WidgetCreator : public ModuleBase_IWidgetCreator -{ -public: - /// Default constructor - FeaturesPlugin_WidgetCreator(); - - /// Virtual destructor - ~FeaturesPlugin_WidgetCreator() {} - - /// Returns a container of possible page types, which this creator can process - /// \param theTypes a list of type names - virtual void widgetTypes(std::set& theTypes); - - /// Create widget by its type - /// The default implementation is empty - /// \param theType a type - /// \param theParent a parent widget - /// \param theData a low-level API for reading xml definitions of widgets - /// \param theWorkshop a current workshop - /// \return a created model widget or null - virtual ModuleBase_ModelWidget* createWidgetByType(const std::string& theType, - QWidget* theParent, - Config_WidgetAPI* theWidgetApi, - ModuleBase_IWorkshop* /*theWorkshop*/); -private: - std::set myPanelTypes; ///< types of panels -}; - -#endif \ No newline at end of file diff --git a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp b/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp deleted file mode 100644 index 377873745..000000000 --- a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp +++ /dev/null @@ -1,720 +0,0 @@ -// Copyright (C) 2014-2020 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 -// - -#include "FeaturesPlugin_WidgetFilletMultiRadiuses.h" -#include "FeaturesPlugin_Fillet.h" - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - - -const char* MYFirstCol = "Shape"; -const char* MYTrue = "True"; -const char* MYFalse = "False"; - - -DataArrayItemDelegate::DataArrayItemDelegate(bool theTypeMethode) - : QStyledItemDelegate(), myTypeMethodePoint(theTypeMethode) -{ -} - - -QWidget* DataArrayItemDelegate::createEditor(QWidget* theParent, - const QStyleOptionViewItem & theOption, - const QModelIndex& theIndex ) const -{ - QWidget* aEditor = 0; - if ((theIndex.column() == 0) && (theIndex.row() > 0 )) { - QWidget* aWgt = QStyledItemDelegate::createEditor(theParent, theOption, theIndex); - QLineEdit* aEdt = static_cast(aWgt); - aEdt->setReadOnly(true); - aEditor = aEdt; - } else { - QLineEdit* aLineEdt = 0; - - aLineEdt = dynamic_cast(QStyledItemDelegate::createEditor(theParent, - theOption, - theIndex)); - if (aLineEdt) { - if( theIndex.column() == 2 ) - aLineEdt->setValidator(new QDoubleValidator(0.0 , 10000.0, 6, aLineEdt)); - else - aLineEdt->setValidator(new QDoubleValidator(0.00001 , 0.9999, 6, aLineEdt)); - aEditor = aLineEdt; - } - - } - - connect(aEditor, SIGNAL(textEdited(const QString&)), - SLOT(onEditItem(const QString&))); - return aEditor; -} - -void DataArrayItemDelegate::onEditItem(const QString& theText) -{ - QWidget* aWgt = dynamic_cast(sender()); - commitData(aWgt); -} - - -//********************************************************************************** -//********************************************************************************** -//********************************************************************************** -FeaturesPlugin_WidgetFilletMultiRadiuses:: - FeaturesPlugin_WidgetFilletMultiRadiuses(QWidget* theParent, - ModuleBase_IWorkshop* theWorkshop, - const Config_WidgetAPI* theData, - bool TypeMethodeBypoint): -ModuleBase_WidgetSelector(theParent, theWorkshop, theData), myHeaderEditor(0), - myTypeMethodeBypoint(TypeMethodeBypoint),mySetSelection(true) -{ - QVBoxLayout* aMainLayout = new QVBoxLayout(this); - - aMainLayout->addWidget(new QLabel("Radii", this)); - // Radiuses controls - QFrame* aRadiusesFrame = new QFrame(this); - aRadiusesFrame->setFrameShape( QFrame::HLine ); - aRadiusesFrame->setFrameShape(QFrame::Box); - aRadiusesFrame->setFrameStyle(QFrame::StyledPanel); - QVBoxLayout* aRadiusesLayout = new QVBoxLayout(); - - - myDataTbl = new QTableWidget(2, 3, aRadiusesFrame); - - myDelegate = new DataArrayItemDelegate(myTypeMethodeBypoint); - - myDataTbl->installEventFilter(this); - myDataTbl->setItemDelegate(myDelegate); - - myDataTbl->verticalHeader()->hide(); - myDataTbl->setRowHeight(0, 25); - myDataTbl->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); - - if(myTypeMethodeBypoint){ - myfirstRowValue.push_back("Start extremity"); - myfirstRowValue.push_back("0"); - myfirstRowValue.push_back("0.5"); - myLastRowValue.push_back("End extremity"); - myLastRowValue.push_back("1"); - myLastRowValue.push_back("0.5"); - }else{ - myfirstRowValue.push_back("0"); - myfirstRowValue.push_back("0"); - myfirstRowValue.push_back("1"); - myLastRowValue.push_back("1"); - myLastRowValue.push_back("1"); - myLastRowValue.push_back("2"); - } - - if(myTypeMethodeBypoint) - myDataTbl->hideColumn(1); - else - myDataTbl->hideColumn(0); - - QStringList aHeaders; - aHeaders << "Point"; - aHeaders << "Curvilinear Abscissa"; - aHeaders << "Radius"; - - - myDataTbl->setHorizontalHeaderLabels(aHeaders); - - QTableWidgetItem* aItem; - for(int j =0; j<3;j++) - { - aItem = new QTableWidgetItem(myfirstRowValue[j]); - if(j==0 || j== 1) - aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled); - myDataTbl->setItem(0, j, aItem); - aItem = new QTableWidgetItem(myLastRowValue[j]); - if(j==0 || j== 1) - aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled); - myDataTbl->setItem(1, j, aItem); - } - - connect(myDataTbl, SIGNAL(cellChanged(int, int)), SLOT(onTableEdited(int, int))); - - myDataTbl->horizontalHeader()->viewport()->installEventFilter(this); - - aRadiusesLayout->addWidget(myDataTbl); - ///======================== - - // Buttons below - QWidget* aBtnWgt = new QWidget(this); - aRadiusesLayout->addWidget(aBtnWgt); - QHBoxLayout* aBtnLayout = new QHBoxLayout(aBtnWgt); - aBtnLayout->setAlignment(Qt::AlignLeft); - aBtnLayout->setContentsMargins(0, 0, 0, 0); - - QPushButton* aAddBtn = new QPushButton(tr("+"), aBtnWgt); - QFont font = aAddBtn->font(); - font.setPointSize(12); - aAddBtn->setFont(font); - aBtnLayout->addWidget(aAddBtn); - aBtnLayout->addStretch(1); - - myRemoveBtn = new QPushButton(tr("-"), aBtnWgt); - font = myRemoveBtn->font(); - font.setPointSize(12); - myRemoveBtn->setFont(font); - aBtnLayout->addWidget(myRemoveBtn); - - aRadiusesFrame->setLayout(aRadiusesLayout ) ; - aMainLayout->addWidget(aRadiusesFrame); - - connect(aAddBtn, SIGNAL(clicked(bool)), SLOT(onAdd())); - connect(myRemoveBtn, SIGNAL(clicked(bool)), SLOT(onRemove())); - connect(qApp, SIGNAL(focusChanged(QWidget*, QWidget*)), SLOT(onFocusChanged(QWidget*, QWidget*))); -} - -QList FeaturesPlugin_WidgetFilletMultiRadiuses::getControls() const -{ - QList aControls; - // this control will accept focus and will be highlighted in the Property Panel - aControls.append(myDataTbl); - return aControls; -} - -//********************************************************************************** -QIntList FeaturesPlugin_WidgetFilletMultiRadiuses::shapeTypes() const -{ - QIntList aRes; - - aRes.append(ModuleBase_Tools::shapeType("vertex")); - return aRes; -} - -//********************************************************************************** -void FeaturesPlugin_WidgetFilletMultiRadiuses::deactivate() -{ - - ModuleBase_WidgetSelector::deactivate(); - storeValueCustom(); -} - -//********************************************************************************** -bool FeaturesPlugin_WidgetFilletMultiRadiuses::eventFilter(QObject* theObject, QEvent* theEvent) -{ - QObject* aObject = 0; - - if (myDataTbl->horizontalHeader()->viewport() == theObject) { - aObject = theObject; - } - if (aObject) { - if (theEvent->type() == QEvent::MouseButtonDblClick) { - if (myHeaderEditor) { //delete previous editor - myHeaderEditor->deleteLater(); - myHeaderEditor = 0; - } - QMouseEvent* aMouseEvent = static_cast(theEvent); - QHeaderView* aHeader = static_cast(aObject->parent()); - QTableWidget* aTable = static_cast(aHeader->parentWidget()); - - int aShift = aTable->horizontalScrollBar()->value(); - int aPos = aMouseEvent->x(); - int aIndex = aHeader->logicalIndex(aHeader->visualIndexAt(aPos)); - if (aIndex > 0) { - QRect aRect; - aRect.setLeft(aHeader->sectionPosition(aIndex)); - aRect.setWidth(aHeader->sectionSize(aIndex)); - aRect.setTop(0); - aRect.setHeight(aHeader->height()); - aRect.adjust(1, 1, -1, -1); - aRect.translate(-aShift, 0); - - myHeaderEditor = new QLineEdit(aHeader->viewport()); - myHeaderEditor->move(aRect.topLeft()); - myHeaderEditor->resize(aRect.size()); - myHeaderEditor->setFrame(false); - QString aText = aHeader->model()-> - headerData(aIndex, aHeader->orientation()).toString(); - myHeaderEditor->setText(aText); - myHeaderEditor->setFocus(); - //myEditIndex = aIndex; //save for future use - myHeaderEditor->installEventFilter(this); //catch focus out event - //if user presses Enter it should close editor - connect(myHeaderEditor, SIGNAL(returnPressed()), aTable, SLOT(setFocus())); - myHeaderEditor->show(); - return true; - } - } - } else if (theEvent->type() == QEvent::FocusIn) { - - QTableWidget* aTable = dynamic_cast(theObject); - if (aTable) { - ModuleBase_IPropertyPanel* aPanel = myWorkshop->propertyPanel(); - if (aPanel->activeWidget() != this) { - aPanel->activateWidget(this, false); - } - } - } - else if (theEvent->type() == QEvent::Show ) { - - /* ModuleBase_IPropertyPanel* aPanel = myWorkshop->propertyPanel(); - if (aPanel->activeWidget() != this) { - aPanel->activateWidget(this, false); - }*/ - DataPtr aData = myFeature->data(); - if( myTypeMethodeBypoint ) - aData->string(FeaturesPlugin_Fillet::CREATION_METHOD_MULTIPLES_RADIUSES()) - ->setValue(FeaturesPlugin_Fillet::CREATION_METHOD_BY_POINTS() ); - else - aData->string(FeaturesPlugin_Fillet::CREATION_METHOD_MULTIPLES_RADIUSES()) - ->setValue(FeaturesPlugin_Fillet::CREATION_METHOD_BY_CURVILEAR_ABSCISSA() ); - } - return ModuleBase_WidgetSelector::eventFilter(theObject, theEvent); -} - - - -//********************************************************************************** -bool FeaturesPlugin_WidgetFilletMultiRadiuses::storeValueCustom() -{ - DataPtr aData = myFeature->data(); - - AttributeTablesPtr aTablesAttr; - - if(myTypeMethodeBypoint) - aTablesAttr = aData->tables(FeaturesPlugin_Fillet::VALUES_ID()); - else - aTablesAttr = aData->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); - - // Store data- - int aRows = myDataTbl->rowCount(); - - aTablesAttr->setSize(aRows, 2); - aTablesAttr->setType(ModelAPI_AttributeTables::ValueType::DOUBLE); - - for (int i = 0; i < aRows; i++) { - for (int j = 0; j < 2; j++) { - QString aTblVal = myDataTbl->item(i, j+1)->text(); - aTablesAttr->setValue( getValue( aTblVal ), i, j); - } - } - - return true; -} - -//********************************************************************************** -bool FeaturesPlugin_WidgetFilletMultiRadiuses::restoreValueCustom() -{ - - if ( !mySetSelection) { - mySetSelection = true; - return false; - } - DataPtr aData = myFeature->data(); - - AttributeTablesPtr aTablesAttr; - - if(myTypeMethodeBypoint) - aTablesAttr = aData->tables(FeaturesPlugin_Fillet::VALUES_ID()); - else - aTablesAttr = aData->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); - - AttributeSelectionPtr anEdges = - std::dynamic_pointer_cast(aData->attribute(FeaturesPlugin_Fillet::EDGE_SELECTED_ID())); - - - - std::map> aValuesSort; - - double res; - int aRows = 0; - std::map>::iterator itValuesSort; - if(myTypeMethodeBypoint) - { - if( !anEdges->isInitialized() ) - return; - - GeomEdgePtr anEdge = GeomEdgePtr(new GeomAPI_Edge( anEdges->value())); - GeomPointPtr first = anEdge->firstPoint(); - GeomPointPtr last = anEdge->lastPoint(); - double taille = first->distance(last); - - std::shared_ptr aCurve(new GeomAPI_Curve(anEdges->value())); - - // Load points - AttributeSelectionListPtr aSelectionListAttr = aData->selectionList(FeaturesPlugin_Fillet::ARRAY_POINT_RADIUS_BY_POINTS()); - AttributeDoubleArrayPtr aArrayAttr; - ListOfShape aPoints; - - std::set aContexts; - for (int anIndex = 0; anIndex < aSelectionListAttr->size(); ++anIndex) { - AttributeSelectionPtr aSelection = aSelectionListAttr->value(anIndex); - GeomShapePtr aShape = aSelection->value(); - - ResultPtr aContext = aSelection->context(); - aContexts.insert(aContext->shape()); - - if (!aShape.get()) { - aShape = aContext->shape(); - } - - aPoints.push_back(aShape); - } - int i =0; - - ListOfShape::const_iterator aPointsIt = aPoints.begin(); - for (; aPointsIt != aPoints.end(); ++aPointsIt) { - AttributeSelectionPtr attsel = aSelectionListAttr->value(i); - std::shared_ptr aPnt = GeomAlgoAPI_PointBuilder::point(*aPointsIt); - std::shared_ptr aPntCurv = aCurve->project(aPnt); - res = (aPntCurv->distance(first) / taille); - QString aName = QString::fromStdWString(attsel->namingName()); - QString aRad = findRadius( QString::number(res) ); - if ( aValuesSort.find( res ) == aValuesSort.end() ) - aValuesSort[ res ] = std::make_pair(aName, aRad ); - i++; - } - - res = 0.0; - aValuesSort[ res ] = std::make_pair (myfirstRowValue[0], findRadius( QString::number(res) )) ; - res = 1.0; - aValuesSort[ res ] = std::make_pair (myLastRowValue[0], findRadius( QString::number(res) )) ; - aRows = aValuesSort.size(); - }else{ - - ModelAPI_AttributeTables::Value aVal; - if (aTablesAttr->isInitialized()){ - - for (int anIndex = 0; anIndex < aTablesAttr->rows(); ++anIndex) { - aVal = aTablesAttr->value(anIndex,0); - double curv = getValueText(aVal).toDouble(); - if ( aValuesSort.find( curv ) == aValuesSort.end() ) - aValuesSort[ curv ] = std::make_pair(getValueText(aVal), findRadius(getValueText(aVal))); - } - aRows = aTablesAttr->rows(); - }else{ - res = 0.0; - aValuesSort[ res ] = std::make_pair (myfirstRowValue[0], myfirstRowValue[2]) ; - res = 1.0; - aValuesSort[ res ] = std::make_pair (myLastRowValue[0], myLastRowValue[2]) ; - aRows = 2; - } - - } - - QTableWidgetItem* aItem = 0; - myDataTbl->blockSignals(true); - aItem = myDataTbl->item( myDataTbl->rowCount() -1, 0 ); - aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); - aItem = myDataTbl->item( myDataTbl->rowCount() -1, 1 ); - aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable); - - - myDataTbl->setRowCount(aRows); - - itValuesSort = aValuesSort.begin(); - - for (int k = 0; k < aRows; k++, ++itValuesSort ) { - - std::pair elem = itValuesSort->second; - QString aCurv = QString::number(itValuesSort->first); - - aItem = myDataTbl->item(k, 0); - if (aItem) { - aItem->setText( elem.first); - } else { - aItem = new QTableWidgetItem(elem.first); - myDataTbl->setItem(k, 0, aItem); - } - aItem = myDataTbl->item(k, 1); - if (aItem) { - aItem->setText( aCurv); - } else { - aItem = new QTableWidgetItem(aCurv); - myDataTbl->setItem(k, 1, aItem); - } - aItem = myDataTbl->item(k, 2); - if (aItem) { - aItem->setText( elem.second); - } else { - aItem = new QTableWidgetItem(elem.second); - myDataTbl->setItem(k, 2, aItem); - } - } - aItem = myDataTbl->item(myDataTbl->rowCount()-1, 0 ); - aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled ); - aItem = myDataTbl->item(myDataTbl->rowCount()-1, 1 ); - aItem->setFlags(Qt::NoItemFlags | Qt::ItemIsEnabled ); - myDataTbl->blockSignals(false); - - return true; -} - - -//********************************************************************************** -void FeaturesPlugin_WidgetFilletMultiRadiuses::onAdd() -{ - - QModelIndex index = myDataTbl->currentIndex(); - int i = index.row(); - if( i == -1 ) - return false; - - if( !myDataTbl->currentItem()->isSelected() && myDataTbl->rowCount() >2 ) - return false; - - myDataTbl->blockSignals(true); - - if ( i == myDataTbl->rowCount() -1) - i = myDataTbl->rowCount() - 2; - - if ( i == 0) - i = 1; - else - i= i+1; - - - myDataTbl->model()->insertRow(i); - QTableWidgetItem* aItem =0; - - aItem = myDataTbl->item( i, 0 ); - aItem = new QTableWidgetItem( "New" ); - myDataTbl->setItem(i, 0, aItem); - aItem = new QTableWidgetItem(myfirstRowValue[1]); - myDataTbl->setItem(i, 1, aItem); - aItem = new QTableWidgetItem("-1"); - myDataTbl->setItem(i, 1, aItem); - aItem = new QTableWidgetItem(myfirstRowValue[2]); - myDataTbl->setItem(i, 2, aItem); - aItem = new QTableWidgetItem(myLastRowValue[2]); - myDataTbl->setItem(i, 2, aItem); - myDataTbl->blockSignals(false); - - emit valuesChanged(); - myDataTbl->setCurrentCell( i, 0); -} - -//********************************************************************************** -void FeaturesPlugin_WidgetFilletMultiRadiuses::onRemove() -{ - QModelIndex index = myDataTbl->currentIndex(); - - if( !myDataTbl->currentItem()->isSelected() && myDataTbl->rowCount() >2 ) - return false; - - myDataTbl->blockSignals(true); - if (index.row() == -1 - || index.row() == 0 - || index.row() == myDataTbl->rowCount() -1) - return; - - if (myTypeMethodeBypoint) - { - QTableWidgetItem* aItem = 0; - - QString aName = myDataTbl->item( index.row() , 0 )->text(); - AttributeSelectionListPtr aSelList = - myFeature->data()->selectionList(FeaturesPlugin_Fillet::ARRAY_POINT_RADIUS_BY_POINTS()); - - AttributeSelectionPtr aAttr; - for (int i = 0; i < aSelList->size(); i++) { - aAttr = aSelList->value(i); - if( aName == QString::fromStdWString( aAttr->namingName()) ) - { - aSelList->remove({i}); - } - } - } - myDataTbl->model()->removeRow(index.row()); - myDataTbl->blockSignals(false); - - emit valuesChanged(); -} - -//********************************************************************************** -void FeaturesPlugin_WidgetFilletMultiRadiuses::onTableEdited(int theRow, int theCol) -{ - // Do not store here column of names - if (theCol == 0) - return; - - if (!myFeature.get()) - return; - - ModelAPI_AttributeTables::Value aVal = getValue(myDataTbl->item(theRow, theCol)->text()); - - AttributeTablesPtr aTablesAttr; - - if(myTypeMethodeBypoint) - aTablesAttr = myFeature->data()->tables(FeaturesPlugin_Fillet::VALUES_ID()); - else - aTablesAttr = myFeature->data()->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); - - if (aTablesAttr->isInitialized()) - { - aTablesAttr->setValue(aVal,theRow, theCol - 1); - emit valuesChanged(); - } -} - -//********************************************************************************** -bool FeaturesPlugin_WidgetFilletMultiRadiuses:: - isValidSelectionCustom(const std::shared_ptr& thePrs) -{ - return true; -} - -//********************************************************************************** -bool FeaturesPlugin_WidgetFilletMultiRadiuses::processEnter() -{ - - return true; -} - -//********************************************************************************** -bool FeaturesPlugin_WidgetFilletMultiRadiuses:: - setSelection(QList>& theValues, const bool theToValidate) -{ - - if ( theValues.size() > 1 || !myTypeMethodeBypoint || theValues.size() == 0 ) - { - mySetSelection = false; - return false; - } - QModelIndex index = myDataTbl->currentIndex(); - if( index.row() == -1 ) - { - mySetSelection = false; - return false; - } - - if( !myDataTbl->currentItem()->isSelected()){ - mySetSelection = false; - return false; - } - - - AttributeSelectionListPtr aSelList = - myFeature->data()->selectionList(FeaturesPlugin_Fillet::ARRAY_POINT_RADIUS_BY_POINTS()); - - ResultPtr aResult; - GeomShapePtr aShape; - int aNbData = 0; - ModuleBase_ViewerPrsPtr aValue = theValues.first(); - aResult = std::dynamic_pointer_cast(aValue->object()); - aShape = aValue->shape(); - if ( (aResult.get() || aShape.get() ) && !aSelList->isInList(aResult, aShape)) { - aSelList->append(aResult, aShape); - onRemove(); - }else{ - mySetSelection = false; - return false; - } - - return true; -} - -//********************************************************************************** -QList> - FeaturesPlugin_WidgetFilletMultiRadiuses::getAttributeSelection() const -{ - QList> aList; - if(myFeature) { - DataPtr aData = myFeature->data(); - AttributeSelectionListPtr aSelList = - aData->selectionList(FeaturesPlugin_Fillet::ARRAY_POINT_RADIUS_BY_POINTS()); - AttributeSelectionPtr aAttr; - ObjectPtr anObject; - for (int i = 0; i < aSelList->size(); i++) { - aAttr = aSelList->value(i); - ModuleBase_ViewerPrsPtr - aPrs(new ModuleBase_ViewerPrs(aAttr->context(), aAttr->value(), NULL)); - aList.append(aPrs); - } - } - return aList; -} - -//********************************************************************************** -ModelAPI_AttributeTables::Value FeaturesPlugin_WidgetFilletMultiRadiuses::getValue(QString theStrVal) const -{ - ModelAPI_AttributeTables::Value aVal; - aVal.myDouble = theStrVal.toDouble(); - return aVal; -} - -//********************************************************************************** -QString FeaturesPlugin_WidgetFilletMultiRadiuses::findRadius(QString thename) const -{ - AttributeTablesPtr aTablesAttr; - - if(myTypeMethodeBypoint) - aTablesAttr = myFeature->data()->tables(FeaturesPlugin_Fillet::VALUES_ID()); - else - aTablesAttr = myFeature->data()->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); - - for(int i = 0; i < aTablesAttr->rows(); ++i) - { - ModelAPI_AttributeTables::Value aVal = aTablesAttr->value( i, 0) ; - if( getValueText(aVal) == thename ) - { - aVal = aTablesAttr->value( i, 1); - return getValueText(aVal); - } - } - return "0.5"; -} - -//********************************************************************************** -QString FeaturesPlugin_WidgetFilletMultiRadiuses::getValueText(ModelAPI_AttributeTables::Value& theVal) const -{ - - return QString::number(theVal.myDouble); -} diff --git a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.h b/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.h deleted file mode 100644 index 10eb4ad5f..000000000 --- a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.h +++ /dev/null @@ -1,167 +0,0 @@ -// Copyright (C) 2014-2020 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 -// - -#ifndef FeaturesPlugin_WidgetFilletMultiRadiuses_H -#define FeaturesPlugin_WidgetFilletMultiRadiuses_H - -#include "FeaturesPlugin.h" - -#include -#include -#include - -#include -#include -#include - -class QWidget; -class QLabel; -class QTableWidget; -class QPushButton; -class QTableWidgetItem; -class QLineEdit; - -class DataArrayItemDelegate : public QStyledItemDelegate -{ - Q_OBJECT -public: - DataArrayItemDelegate(bool theTypeMethode); - - virtual QWidget* createEditor(QWidget* theParent, - const QStyleOptionViewItem & theOption, - const QModelIndex& theIndex) const; - -private slots: - void onEditItem(const QString& theText); - -private: - bool myTypeMethodePoint; -}; - - -/*! - * \ingroup GUI - * Represent a content of the property panel to show/modify parameters of a Field feature. - */ -class FeaturesPlugin_WidgetFilletMultiRadiuses : public ModuleBase_WidgetSelector -{ - Q_OBJECT -public: - FeaturesPlugin_WidgetFilletMultiRadiuses(QWidget* theParent, - ModuleBase_IWorkshop* theWorkshop, - const Config_WidgetAPI* theData, - bool TypeMethodeBypoint); - - virtual ~FeaturesPlugin_WidgetFilletMultiRadiuses() {} - - /// Returns true if the event is processed. - virtual bool processEnter(); - - /// The methiod called when widget is deactivated - virtual void deactivate(); - - /// Checks the widget validity. By default, it returns true. - /// \param thePrs a selected presentation in the view - /// \return a boolean value - virtual bool isValidSelectionCustom(const std::shared_ptr& theValue); - -protected: - /// Saves the internal parameters to the given feature - /// \return True in success - virtual bool storeValueCustom(); - - /// Restore value from attribute data to the widget's control - virtual bool restoreValueCustom(); - - /// Redefinition of virtual function - /// \param theObject an object for the event - /// \param theEvent an event - virtual bool eventFilter(QObject* theObject, QEvent* theEvent); - - //virtual void showEvent(QShowEvent* theEvent); - - /// Returns list of widget controls - /// \return a control list - virtual QList getControls() const; - - /// Set the given wrapped value to the current widget - /// This value should be processed in the widget according to the needs - /// \param theValues the wrapped selection values - /// \param theToValidate a validation of the values flag - virtual bool setSelection(QList>& theValues, - const bool theToValidate); - - /// Return the attribute values wrapped in a list of viewer presentations - /// \return a list of viewer presentations, which contains an attribute result and - /// a shape. If the attribute do not uses the shape, it is empty - virtual QList> getAttributeSelection() const; - -private slots: - - /// Slot called on add a row - void onAdd(); - - /// Slot called on remove a row - void onRemove(); - - /// Retunrs a list of possible shape types - /// \return a list of shapes - virtual QIntList shapeTypes() const; - - /// Slot called on editing of a table cell - /// \param theRow a row of the cell - /// \param theCol a column of the cell - void onTableEdited(int theRow, int theCol); - - -private: - - /// Return a value from the string - /// \param theStrVal a string - ModelAPI_AttributeTables::Value getValue(QString theStrVal) const; - - /// Return a QString from the ModelAPI_AttributeTables - /// \param theStrVal a string - QString getValueText(ModelAPI_AttributeTables::Value& theVal) const; - - /// Return a radii value from the name - /// \param theStrVal a string - QString findRadius(QString thename) const; - - /// tables - QTableWidget* myDataTbl; - - /// Remove button - QPushButton* myRemoveBtn; - - /// Editor for table header - QLineEdit* myHeaderEditor; - - bool myTypeMethodeBypoint; - - bool mySetSelection; - - DataArrayItemDelegate* myDelegate; - - std::vector myfirstRowValue; - std::vector myLastRowValue; - -}; - -#endif \ No newline at end of file diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp deleted file mode 100644 index 3e2a700cf..000000000 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp +++ /dev/null @@ -1,446 +0,0 @@ -// Copyright (C) 2014-2020 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 -// - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC - - -//============================================================================= -/*! - * GetShape() - */ -//============================================================================= - -TopoDS_Shape GetShape(const Handle(Standard_Transient) &theEnti, - const Handle(Transfer_TransientProcess) &theTP) -{ - TopoDS_Shape aResult; - Handle(Transfer_Binder) aBinder = theTP->Find(theEnti); - - if (aBinder.IsNull()) { - return aResult; - } - - aResult = TransferBRep::ShapeResult(aBinder); - - return aResult; -} - -// ---------------------------------------------------------------------------- - -std::shared_ptr readAttributes( STEPCAFControl_Reader &reader, - std::shared_ptr theResultBody, - const bool anMaterials, - std::map< std::wstring, std::list> &theMaterialShape, - const std::string &format) -{ - // dummy XCAF Application to handle the STEP XCAF Document - Handle(XCAFApp_Application) dummy_app = XCAFApp_Application::GetApplication(); - // XCAF Document to contain the STEP/IGES file itself - Handle(TDocStd_Document) doc; - // check if a file is already open under this handle, if so, close it to - // prevent segfaults when trying to create a new document - if(dummy_app->NbDocuments() > 0) { - dummy_app->GetDocument(1, doc); - dummy_app->Close(doc); - } - - dummy_app->NewDocument( TCollection_ExtendedString("MDTV-CAF"), doc); - // transfer STEP/IGES into the document, and get the main label - reader.Transfer(doc); - TDF_Label mainLabel = doc->Main(); - Handle_XCAFDoc_ShapeTool shapeTool = XCAFDoc_DocumentTool::ShapeTool(mainLabel); - Handle_XCAFDoc_ColorTool colorTool = XCAFDoc_DocumentTool::ColorTool(mainLabel); - Handle(XCAFDoc_MaterialTool) materialTool = XCAFDoc_DocumentTool::MaterialTool(mainLabel); - // traverse the labels recursively to set attributes on shapes - setShapeAttributes(shapeTool, colorTool, materialTool, mainLabel, - TopLoc_Location(),theResultBody,theMaterialShape,false); - - - std::shared_ptr ageom = setgeom(shapeTool,mainLabel); - - STEPControl_Reader aReader = reader.ChangeReader(); - - // BEGIN: reading materials of sub-shapes from file - if ( anMaterials ) - { - TopTools_IndexedMapOfShape anIndices; - TopExp::MapShapes(ageom->impl(), anIndices); - - Handle(Interface_InterfaceModel) Model = aReader.WS()->Model(); - Handle(XSControl_TransferReader) TR = aReader.WS()->TransferReader(); - if (!TR.IsNull()) { - Handle(Transfer_TransientProcess) TP = TR->TransientProcess(); - - Standard_Integer nb = Model->NbEntities(); - - for (Standard_Integer ie = 1; ie <= nb; ie++) { - Handle(Standard_Transient) enti = Model->Value(ie); - - // Store materials. - StoreMaterial(theResultBody,enti, anIndices, TP, mainLabel,theMaterialShape); - } - } - } - - return ageom; -} - -std::shared_ptr setgeom(const Handle(XCAFDoc_ShapeTool) &shapeTool, - const TDF_Label &label) -{ - BRep_Builder B; - TopoDS_Compound compound; - B.MakeCompound(compound); - - TDF_LabelSequence frshapes; - shapeTool->GetShapes(frshapes); - - std::shared_ptr aGeomShape(new GeomAPI_Shape); - - if (frshapes.Length() == 0) { - aGeomShape->setImpl(new TopoDS_Shape()); - return aGeomShape; - } else if (frshapes.Length() == 1) { - TopoDS_Shape shape = shapeTool->GetShape(frshapes.Value(1)); - aGeomShape->setImpl(new TopoDS_Shape(shape)); - return aGeomShape; - } else { - for (Standard_Integer i=1; iGetShape(frshapes.Value(i)); - - TDF_Label aLabel = shapeTool->FindShape(S, Standard_False); - if ( (!aLabel.IsNull()) && (shapeTool->IsShape(aLabel)) ) { - if (shapeTool->IsFree(aLabel) ) { - if (S.IsNull()) { - continue; - } - else { - B.Add(compound, S); - } - } - } - } - TopoDS_Shape shape = compound; - aGeomShape->setImpl(new TopoDS_Shape(shape)); - return aGeomShape; - } -} - -void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, - const Handle(XCAFDoc_ColorTool) &colorTool, - const Handle(XCAFDoc_MaterialTool) &materialTool, - const TDF_Label &label, - const TopLoc_Location &loc, - std::shared_ptr theResultBody, - std::map< std::wstring, std::list> &theMaterialShape, - bool isRef) -{ - std::wstring shapeName; - Handle(TDataStd_Name) n; - - if(label.FindAttribute(TDataStd_Name::GetID(), n)) { - TCollection_ExtendedString name = n->Get(); - - shapeName = Locale::Convert::toWString(TCollection_AsciiString(name).ToCString()) ; - } - - TopLoc_Location partLoc = loc; - Handle(XCAFDoc_Location) l; - if(label.FindAttribute(XCAFDoc_Location::GetID(), l)) { - if(isRef) - partLoc = partLoc * l->Get(); - else - partLoc = l->Get(); - } - - TDF_Label ref; - if(shapeTool->IsReference(label) && shapeTool->GetReferredShape(label, ref)) { - - setShapeAttributes( shapeTool, colorTool, materialTool, ref, - partLoc,theResultBody,theMaterialShape,true); - } - - if( shapeTool->IsSimpleShape(label) && (isRef || shapeTool->IsFree(label))) { - - TopoDS_Shape shape = shapeTool->GetShape(label); - - std::shared_ptr aShapeGeom(new GeomAPI_Shape); - if (!loc.IsIdentity()){ - shape.Move(loc); - } - aShapeGeom->setImpl(new TopoDS_Shape(shape)); - shapeName = theResultBody->addShapeName(aShapeGeom, shapeName); - - - shape.Location(isRef ? loc : partLoc); - int dim = - (shape.ShapeType() == TopAbs_VERTEX) ? - 0 : - (shape.ShapeType() == TopAbs_EDGE || shape.ShapeType() == TopAbs_WIRE) ? - 1 : - (shape.ShapeType() == TopAbs_FACE || - shape.ShapeType() == TopAbs_SHELL) ? 2 :3; - - Handle(TCollection_HAsciiString) matName; - Handle(TCollection_HAsciiString) matDescription; - Standard_Real matDensity; - Handle(TCollection_HAsciiString) matDensName; - Handle(TCollection_HAsciiString) matDensValType; - - if(materialTool->GetMaterial(label, matName, matDescription, matDensity, - matDensName, matDensValType)) { - std::wstring nameMaterial = Locale::Convert::toWString(matName->ToCString()); - - theMaterialShape[nameMaterial].push_back(shapeName); - } - - - Quantity_Color col; - if(colorTool->GetColor(label, XCAFDoc_ColorGen, col)) { - double r = col.Red(), g = col.Green(), b = col.Blue(); - std::vector ColRGB = {int(r*255),int(g*255),int(b*255)}; - theResultBody->addShapeColor(shapeName, ColRGB); - } - else if(colorTool->GetColor(label, XCAFDoc_ColorSurf, col)) { - double r = col.Red(), g = col.Green(), b = col.Blue(); - std::vector ColRGB = {int(r*255),int(g*255),int(b*255)}; - theResultBody->addShapeColor(shapeName, ColRGB); - } - else if(colorTool->GetColor(label, XCAFDoc_ColorCurv, col)) { - double r = col.Red(), g = col.Green(), b = col.Blue(); - std::vector ColRGB = {int(r*255),int(g*255),int(b*255)}; - theResultBody->addShapeColor(shapeName, ColRGB); - } - // check explicit coloring of boundary entities - if(dim == 3) { - TopExp_Explorer xp2(shape, TopAbs_FACE); - while(xp2.More()) { - if(colorTool->GetColor(xp2.Current(), XCAFDoc_ColorGen, col) || - colorTool->GetColor(xp2.Current(), XCAFDoc_ColorSurf, col) || - colorTool->GetColor(xp2.Current(), XCAFDoc_ColorCurv, col)) { - double r = col.Red(), g = col.Green(), b = col.Blue(); - TopoDS_Face face = TopoDS::Face(xp2.Current()); - std::vector ColRGB = {int(r*255),int(g*255),int(b*255)}; - std::wstringstream aNameFace; - TopoDS_Shape shapeface = xp2.Current(); - if (!loc.IsIdentity()){ - shapeface.Move(loc); - } - aShapeGeom->setImpl(new TopoDS_Shape(shapeface)); - theResultBody->addShapeColor( - theResultBody->addShapeName(aShapeGeom , aNameFace.str()), ColRGB); - } - xp2.Next(); - } - } - if(dim == 2) { - TopExp_Explorer xp1(shape, TopAbs_EDGE); - while(xp1.More()) { - if(colorTool->GetColor(xp1.Current(), XCAFDoc_ColorGen, col) || - colorTool->GetColor(xp1.Current(), XCAFDoc_ColorSurf, col) || - colorTool->GetColor(xp1.Current(), XCAFDoc_ColorCurv, col)) { - double r = col.Red(), g = col.Green(), b = col.Blue(); - std::vector ColRGB = {int(r*255),int(g*255),int(b*255)}; - std::wstringstream aNameEdge; - aNameEdge << L"Edge_"<< shapeName; - aShapeGeom->setImpl(new TopoDS_Shape(xp1.Current() )); - theResultBody->addShapeColor( - theResultBody->addShapeName(aShapeGeom , aNameEdge.str()), ColRGB); - } - xp1.Next(); - } - } - } - else { - int indiceChild = 1; - - if (!shapeTool->IsReference(label)){ - TopoDS_Shape shape = shapeTool->GetShape(label); - - std::shared_ptr aShapeGeom(new GeomAPI_Shape); - if (!loc.IsIdentity()){ - shape.Move(loc); - } - aShapeGeom->setImpl(new TopoDS_Shape(shape)); - shapeName = theResultBody->addShapeName(aShapeGeom, shapeName); - } - for(TDF_ChildIterator it(label); it.More(); it.Next()) { - - setShapeAttributes( shapeTool, colorTool, materialTool, - it.Value(), partLoc,theResultBody,theMaterialShape, isRef); - indiceChild++; - } - } -} - - -//============================================================================= - /*! - * StoreMaterial() - */ - //============================================================================= - - void StoreMaterial( std::shared_ptr theResultBody, - const Handle(Standard_Transient) &theEnti, - const TopTools_IndexedMapOfShape &theIndices, - const Handle(Transfer_TransientProcess) &theTP, - const TDF_Label &theShapeLabel, - std::map< std::wstring, std::list> &theMaterialShape ) - { - // Treat Product Definition Shape only. - Handle(StepRepr_ProductDefinitionShape) aPDS = - Handle(StepRepr_ProductDefinitionShape)::DownCast(theEnti); - Handle(StepBasic_ProductDefinition) aProdDef; - - if(aPDS.IsNull() == Standard_False) { - // Product Definition Shape ==> Product Definition - aProdDef = aPDS->Definition().ProductDefinition(); - } - - if (aProdDef.IsNull() == Standard_False) { - // Product Definition ==> Property Definition - const Interface_Graph &aGraph = theTP->Graph(); - Interface_EntityIterator aSubs = aGraph.Sharings(aProdDef); - TopoDS_Shape aShape; - - for(aSubs.Start(); aSubs.More(); aSubs.Next()) { - Handle(StepRepr_PropertyDefinition) aPropD = - Handle(StepRepr_PropertyDefinition)::DownCast(aSubs.Value()); - - if(aPropD.IsNull() == Standard_False) { - // Property Definition ==> Representation. - Interface_EntityIterator aSubs1 = aGraph.Sharings(aPropD); - - for(aSubs1.Start(); aSubs1.More(); aSubs1.Next()) { - Handle(StepRepr_PropertyDefinitionRepresentation) aPDR = - Handle(StepRepr_PropertyDefinitionRepresentation):: - DownCast(aSubs1.Value()); - - if(aPDR.IsNull() == Standard_False) { - // Property Definition ==> Material Name. - Handle(StepRepr_Representation) aRepr = aPDR->UsedRepresentation(); - - if(aRepr.IsNull() == Standard_False) { - Standard_Integer ir; - - for(ir = 1; ir <= aRepr->NbItems(); ir++) { - Handle(StepRepr_RepresentationItem) aRI = aRepr->ItemsValue(ir); - Handle(StepRepr_DescriptiveRepresentationItem) aDRI = - Handle(StepRepr_DescriptiveRepresentationItem)::DownCast(aRI); - - if(aDRI.IsNull() == Standard_False) { - // Get shape from Product Definition - Handle(TCollection_HAsciiString) aMatName = aDRI->Name(); - if(aMatName.IsNull() == Standard_False) { - TCollection_ExtendedString - aMatNameExt (aMatName->ToCString()); - - if (aShape.IsNull()) { - //Get the shape. - aShape = GetShape(aProdDef, theTP); - if (aShape.IsNull()) { - return; - } - } - - // as PRODUCT can be included in the main shape - // several times, we look here for all iclusions. - Standard_Integer isub, nbSubs = theIndices.Extent(); - - for (isub = 1; isub <= nbSubs; isub++) { - TopoDS_Shape aSub = theIndices.FindKey(isub); - - if (aSub.IsPartner(aShape)) { - std::shared_ptr aShapeGeom(new GeomAPI_Shape); - aShapeGeom->setImpl(new TopoDS_Shape(aSub)); - std::wstring nom = theResultBody->findShapeName(aShapeGeom); - std::wstring matName= Locale::Convert::toWString(aMatName->ToCString()); - theMaterialShape[matName].push_back(nom); - - } - } - } - } - } - } - } - } - } - } - } - } - diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h b/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h deleted file mode 100644 index 2955a5308..000000000 --- a/src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (C) 2014-2020 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 -// - -#ifndef GEOMALGOAPI_STEPIMPORTXCAF_H_ -#define GEOMALGOAPI_STEPIMPORTXCAF_H_ - -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - - // read Attributs of step file - GEOMALGOAPI_EXPORT - std::shared_ptr readAttributes( STEPCAFControl_Reader &reader, - std::shared_ptr theResultBody, - const bool anMaterials, - std::map< std::wstring, std::list> &theMaterialShape, - const std::string &format); - // read attributs for label - GEOMALGOAPI_EXPORT - void setShapeAttributes(const Handle(XCAFDoc_ShapeTool) &shapeTool, - const Handle(XCAFDoc_ColorTool) &colorTool, - const Handle(XCAFDoc_MaterialTool) &materialTool, - const TDF_Label &label, - const TopLoc_Location &loc, - std::shared_ptr theResultBody, - std::map< std::wstring, std::list> &theMaterialShape, - bool isRef); - -// read geometry -GEOMALGOAPI_EXPORT -std::shared_ptr setgeom(const Handle(XCAFDoc_ShapeTool) &shapeTool, - const TDF_Label &label); - -// store Materiel for theShapeLabel in the map theMaterialShape -GEOMALGOAPI_EXPORT -void StoreMaterial( std::shared_ptr theResultBody, - const Handle(Standard_Transient) &theEnti, - const TopTools_IndexedMapOfShape &theIndices, - const Handle(Transfer_TransientProcess) &theTP, - const TDF_Label &theShapeLabel, - std::map< std::wstring, std::list> &theMaterialShape ); - -#endif /* GEOMALGOAPI_STEPIMPORTXCAF_H_ */ diff --git a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp index 4699cc1bd..56193ea49 100644 --- a/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp +++ b/src/InitializationPlugin/InitializationPlugin_EvalListener.cpp @@ -49,7 +49,7 @@ #include #include -//------------------------------------------------------------------------------ +//================================================================================================= // Tools std::wstring toString(double theValue) @@ -67,7 +67,7 @@ std::set toSet(const std::list& theContainer) return std::set(theContainer.begin(), theContainer.end()); } -//------------------------------------------------------------------------------ +//================================================================================================= InitializationPlugin_EvalListener::InitializationPlugin_EvalListener() { @@ -82,10 +82,12 @@ InitializationPlugin_EvalListener::InitializationPlugin_EvalListener() myInterp->initialize(); } +//================================================================================================= InitializationPlugin_EvalListener::~InitializationPlugin_EvalListener() { } +//================================================================================================= void InitializationPlugin_EvalListener::processEvent( const std::shared_ptr& theMessage) { @@ -143,7 +145,7 @@ void InitializationPlugin_EvalListener::processEvent( Locale::Convert::toWString(anExprAttr->value()); anExpZ.erase(std::remove(anExpZ.begin(),anExpZ.end(), ' '), anExpZ.end()); - for(int step =0; step < anValueAttr->rows(); step++ ){ + for (int step =0; step < anValueAttr->rows(); step++){ aVal.myDouble = evaluate(anVar, anValueAttr->value(step,0).myDouble, aParam, @@ -151,9 +153,8 @@ void InitializationPlugin_EvalListener::processEvent( anError, aParamsList, anIsFirstTime); - if(!anError.empty()) break; + if (!anError.empty()) break; anValueAttr->setValue(aVal,step,1); - aVal.myDouble = evaluate(anVar, anValueAttr->value(step,0).myDouble, aParam, @@ -161,9 +162,8 @@ void InitializationPlugin_EvalListener::processEvent( anError, aParamsList, anIsFirstTime); - if(!anError.empty()) break; + if (!anError.empty()) break; anValueAttr->setValue(aVal,step,2); - aVal.myDouble = evaluate(anVar, anValueAttr->value(step,0).myDouble, aParam, @@ -171,16 +171,16 @@ void InitializationPlugin_EvalListener::processEvent( anError, aParamsList, anIsFirstTime); - if(!anError.empty()) break; + if (!anError.empty()) break; anValueAttr->setValue(aVal,step,3); - if ( anIsFirstTime ) + if (anIsFirstTime) anIsFirstTime = false; } - aMsg->setResults(aParamsList, anError); } } +//================================================================================================= double InitializationPlugin_EvalListener::evaluate( std::wstring& theVariable, double theValueVariable, @@ -197,9 +197,8 @@ double InitializationPlugin_EvalListener::evaluate( std::list anExprParams = myInterp->compile(theExpression); // find expression's params in the model - std::list::iterator it = anExprParams.begin(); - for ( ; it != anExprParams.end(); it++) { + for (; it != anExprParams.end(); it++) { double aValue; ResultParameterPtr aParamRes; // If variable does not exist python interpreter will generate an error. @@ -207,11 +206,11 @@ double InitializationPlugin_EvalListener::evaluate( *it, aValue, aParamRes, theParameter->document())) continue; - if( theIsFirstTime ) + if (theIsFirstTime) { std::list::iterator anIter = std::find(theParamsList.begin(),theParamsList.end(), aParamRes ); - if(anIter == theParamsList.end()) + if (anIter == theParamsList.end()) theParamsList.push_back(aParamRes); } @@ -223,7 +222,7 @@ double InitializationPlugin_EvalListener::evaluate( return result; } - +//================================================================================================= double InitializationPlugin_EvalListener::evaluate(FeaturePtr theParameter, const std::wstring& theExpression, std::string& theError, std::list >& theParamsList, @@ -253,6 +252,7 @@ double InitializationPlugin_EvalListener::evaluate(FeaturePtr theParameter, return result; } +//================================================================================================= void InitializationPlugin_EvalListener::processEvaluationEvent( const std::shared_ptr& theMessage) { @@ -341,6 +341,7 @@ void InitializationPlugin_EvalListener::processEvaluationEvent( } } +//================================================================================================= void InitializationPlugin_EvalListener::initDataModel() { myInterp->runString("import salome_iapp;salome_iapp.register_module_in_study(\"Shaper\")"); diff --git a/src/ModelAPI/ModelAPI_Events.h b/src/ModelAPI/ModelAPI_Events.h index 06972aa17..e11ab4b06 100644 --- a/src/ModelAPI/ModelAPI_Events.h +++ b/src/ModelAPI/ModelAPI_Events.h @@ -357,7 +357,7 @@ class ModelAPI_BuildEvalMessage : public Events_Message FeaturePtr myParam; ///< parameters that should be evaluated bool myIsProcessed; ///< true if results were set std::string myError; ///< error of processing, empty if there is no error - /// result of processing, list of parameters in expression found + /// result of processing, list of parameters in expression found std::list > myParamsList; public: @@ -375,8 +375,8 @@ class ModelAPI_BuildEvalMessage : public Events_Message send(FeaturePtr theParameter, const void* theSender) { std::shared_ptr aMessage = - std::shared_ptr( - new ModelAPI_BuildEvalMessage(eventId(), theSender)); + std::shared_ptr( + new ModelAPI_BuildEvalMessage(eventId(), theSender)); aMessage->setParameter(theParameter); Events_Loop::loop()->send(aMessage); return aMessage; @@ -393,9 +393,9 @@ class ModelAPI_BuildEvalMessage : public Events_Message MODELAPI_EXPORT void setParameter(FeaturePtr theParam); /// Sets the results of processing MODELAPI_EXPORT void setResults( - const std::list >& theParamsList, - const std::string& theError); - /// Returns the results of processing: list of parameters found in the expression + const std::list >& theParamsList, + const std::string& theError); + /// Returns the results of processing: list of parameters found in the expression MODELAPI_EXPORT const std::list >& params() const; /// Returns true if the expression is processed MODELAPI_EXPORT bool isProcessed(); -- 2.39.2