From 9ab5b25dcb7f4ae1b4a3588e7731c34748847bf2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me?= Date: Thu, 22 Oct 2020 19:58:28 +0200 Subject: [PATCH] refactoring code (cpplint, name...) --- src/FeaturesAPI/FeaturesAPI_Fillet.cpp | 15 +- src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp | 36 +- src/FeaturesPlugin/FeaturesPlugin_Fillet.h | 4 +- .../FeaturesPlugin_VersionedChFi.cpp | 6 +- .../FeaturesPlugin_VersionedChFi.h | 4 +- .../FeaturesPlugin_WidgetCreator.cpp | 12 +- ...aturesPlugin_WidgetFilletMultiRadiuses.cpp | 62 ++- src/GeomAlgoAPI/GeomAlgoAPI_Fillet.cpp | 4 +- src/GeomAlgoAPI/GeomAlgoAPI_Fillet.h | 6 +- .../GeomAlgoAPI_STEPImportXCAF.cpp | 446 ------------------ src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h | 74 --- 11 files changed, 79 insertions(+), 590 deletions(-) delete mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.cpp delete mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_STEPImportXCAF.h diff --git a/src/FeaturesAPI/FeaturesAPI_Fillet.cpp b/src/FeaturesAPI/FeaturesAPI_Fillet.cpp index a62332752..1b0f7172d 100644 --- a/src/FeaturesAPI/FeaturesAPI_Fillet.cpp +++ b/src/FeaturesAPI/FeaturesAPI_Fillet.cpp @@ -213,7 +213,7 @@ FeaturesAPI_Fillet2D::FeaturesAPI_Fillet2D(const std::shared_ptrsetValue(aVal, aRowIndex, 0 ); aVal.myDouble = aRowsRadiusIter->value(); myvalues()->setValue(aVal, aRowIndex, 1 ); - + execute(); } } @@ -226,7 +226,8 @@ FeaturesAPI_Fillet2D::FeaturesAPI_Fillet2D(const std::shared_ptrsetValue(aVal, aRowIndex, 0 ); aVal.myDouble = aRowsRadiusIter->value(); myvaluescurv()->setValue(aVal, aRowIndex, 1 ); - } + } if (myedgesfacesmultiselected->size() > 0) execute(); } @@ -299,7 +300,8 @@ void FeaturesAPI_Fillet2D::dump(ModelHighAPI_Dumper& theDumper) const aBase->selectionList(FeaturesPlugin_Fillet::ARRAY_POINT_RADIUS_BY_POINTS()); AttributeTablesPtr anAttrTable = aBase->tables(FeaturesPlugin_Fillet::VALUES_ID()); - theDumper << aBase << " = model.addFilletMultiRadiusByPoints(" << aDocName << ", " << anAttrEdgeSelec; + theDumper << aBase << " = model.addFilletMultiRadiusByPoints(" + << aDocName << ", " << anAttrEdgeSelec; theDumper << ", " << anAttrPoint ; theDumper<<", ["; for(int aRow = 0; aRow < myvalues()->rows(); aRow++) { @@ -314,7 +316,8 @@ void FeaturesAPI_Fillet2D::dump(ModelHighAPI_Dumper& theDumper) const AttributeSelectionListPtr anAttrEdgesFaces = aBase->selectionList(FeaturesPlugin_Fillet::EDGES_FACES_MULTI_LIST_ID()); AttributeTablesPtr anAttrTable = aBase->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); - theDumper << aBase << " = model.addFilletMultiRadiusBycurvAbs(" << aDocName << ", " << anAttrEdgesFaces; + theDumper << aBase << " = model.addFilletMultiRadiusBycurvAbs(" + << aDocName << ", " << anAttrEdgesFaces; theDumper << ", "; theDumper<<"["; for(int aRow = 0; aRow < myvaluescurv()->rows(); aRow++) { @@ -332,7 +335,7 @@ void FeaturesAPI_Fillet2D::dump(ModelHighAPI_Dumper& theDumper) const theDumper<<"]"; } }else - { + { std::string aCreationMethod = aBase->string(FeaturesPlugin_Fillet::CREATION_METHOD())->value(); diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp index 96054ea28..1fc290423 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet.cpp @@ -65,15 +65,15 @@ void FeaturesPlugin_Fillet::initAttributes() AttributePtr aSelectionList = data()->addAttribute(OBJECT_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); - AttributePtr aSelectionEdgesFacesList = + AttributePtr aSelectionEdgesFacesList = data()->addAttribute(EDGES_FACES_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); - - AttributePtr aSelectionEdgesFacesMultiList = + + AttributePtr aSelectionEdgesFacesMultiList = data()->addAttribute(EDGES_FACES_MULTI_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); - + AttributePtr aSelectionEdgeSelected = data()->addAttribute(EDGE_SELECTED_ID(), ModelAPI_AttributeSelection::typeId()); - + data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); data()->addAttribute(CREATION_MULTI_RADIUS_METHODE(), ModelAPI_AttributeString::typeId()); @@ -86,10 +86,12 @@ void FeaturesPlugin_Fillet::initAttributes() data()->addAttribute(ARRAY_POINT_RADIUS_BY_POINTS(), ModelAPI_AttributeSelectionList::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), END_RADIUS_ID()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ARRAY_POINT_RADIUS_BY_POINTS()); + ModelAPI_Session::get()->validators()-> + registerNotObligatory(getKind(), ARRAY_POINT_RADIUS_BY_POINTS()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), VALUES_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), VALUES_CURV_ID()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), CREATION_MULTI_RADIUS_METHODE()); + ModelAPI_Session::get()->validators()-> + registerNotObligatory(getKind(), CREATION_MULTI_RADIUS_METHODE()); initVersion(aSelectionEdgeSelected); initVersion(aSelectionEdgesFacesMultiList); @@ -99,7 +101,7 @@ void FeaturesPlugin_Fillet::initAttributes() } AttributePtr FeaturesPlugin_Fillet::objectsAttribute() -{ +{ if( string(CREATION_METHOD())->value() == METHOD_MULTIPLES_RADIUSES() ) { if( string(CREATION_MULTI_RADIUS_METHODE())->value() == CREATION_METHOD_BY_POINTS()) @@ -138,34 +140,34 @@ GeomMakeShapePtr FeaturesPlugin_Fillet::performOperation(const GeomShapePtr& the setError(anError); return GeomMakeShapePtr(); } - + std::shared_ptr aFilletBuilder; - + ListOfShape aFilletEdges = extractEdges(theEdges); if ( aCreationMethod->value() == METHOD_MULTIPLES_RADIUSES()) { - std::list coodCurv; - std::list radiuses; + std::list aCoodCurv; + std::list aRadiuses; AttributeTablesPtr aTablesAttr; if( string(CREATION_MULTI_RADIUS_METHODE())->value() == CREATION_METHOD_BY_POINTS() ) { aTablesAttr = tables(VALUES_ID()); - + }else{ aTablesAttr = tables(VALUES_CURV_ID()); } int aRows = aTablesAttr->rows(); ModelAPI_AttributeTables::Value aVal; - for (int k = 0; k < aRows; k++) { + for (int k = 0; k < aRows; k++) { aVal = aTablesAttr->value(k, 0); - coodCurv.push_back(aVal.myDouble); + aCoodCurv.push_back(aVal.myDouble); aVal = aTablesAttr->value(k, 1); - radiuses.push_back(aVal.myDouble); + aRadiuses.push_back(aVal.myDouble); } - aFilletBuilder.reset(new GeomAlgoAPI_Fillet(theSolid, aFilletEdges, coodCurv,radiuses)); + aFilletBuilder.reset(new GeomAlgoAPI_Fillet(theSolid, aFilletEdges, aCoodCurv,aRadiuses)); }else { diff --git a/src/FeaturesPlugin/FeaturesPlugin_Fillet.h b/src/FeaturesPlugin/FeaturesPlugin_Fillet.h index b8d11935d..817592837 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_Fillet.h +++ b/src/FeaturesPlugin/FeaturesPlugin_Fillet.h @@ -108,7 +108,7 @@ public: /// Attribute name of main objects. inline static const std::string& EDGES_FACES_MULTI_LIST_ID() { - static const std::string + static const std::string MY_EDGES_FACES_MULTI_LIST_ID("edges_faces_seleted_multi"); return MY_EDGES_FACES_MULTI_LIST_ID; } @@ -132,7 +132,7 @@ public: static const std::string MY_VALUES_ID("values"); return MY_VALUES_ID; } - + /// attribute name of list of tables that contain deafult values (row 0) and the custom values inline static const std::string& VALUES_CURV_ID() { diff --git a/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp b/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp index 51bba73a3..ede9bb1d5 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.cpp @@ -119,7 +119,7 @@ bool FeaturesPlugin_VersionedChFi::processAttribute(const AttributePtr& theAttri if( anObject.get() ) { - if ( !addShapeInHierarchy(anObject , theObjects, isStoreFullHierarchy) ) + if ( !addShapeInHierarchy(anObject , theObjects, isStoreFullHierarchy) ) return false; return true; } @@ -128,7 +128,7 @@ bool FeaturesPlugin_VersionedChFi::processAttribute(const AttributePtr& theAttri for (int anObjectsIndex = 0; anObjectsIndex < anObjectsSelList->size(); ++anObjectsIndex) { AttributeSelectionPtr anObjectAttr = anObjectsSelList->value(anObjectsIndex); - if ( !addShapeInHierarchy(anObjectAttr , theObjects, isStoreFullHierarchy) ) + if ( !addShapeInHierarchy(anObjectAttr , theObjects, isStoreFullHierarchy) ) return false; } return true; @@ -168,7 +168,7 @@ bool FeaturesPlugin_VersionedChFi::addShapeInHierarchy(const AttributeSelectionP theObjects.addObject(anObject); theObjects.addParent(anObject, aParent); } - + if (theIsStoreFullHierarchy) ModelAPI_Tools::fillShapeHierarchy(aParent, aContext, theObjects); } else { // get it from a feature diff --git a/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.h b/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.h index 8e51fe6e4..de48fc201 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.h +++ b/src/FeaturesPlugin/FeaturesPlugin_VersionedChFi.h @@ -49,8 +49,8 @@ protected: /// Process SelectionList attribute and fill the objects hierarchy. bool processAttribute(const std::shared_ptr& theAttribute, GeomAPI_ShapeHierarchy& theObjects); - - // Add Shape in the object hierarchy + + // Add Shape in the object hierarchy bool addShapeInHierarchy(const AttributeSelectionPtr& theAttribute, GeomAPI_ShapeHierarchy& theObjects, bool theIsStoreFullHierarchy); diff --git a/src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.cpp b/src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.cpp index 05478d8bc..310ef8388 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_WidgetCreator.cpp @@ -45,12 +45,18 @@ ModuleBase_ModelWidget* FeaturesPlugin_WidgetCreator::createWidgetByType( return aWidget; if (theType == "multiradius-panel") { - aWidget = new FeaturesPlugin_WidgetFilletMultiRadiuses(theParent, theWorkshop, theWidgetApi, true); + aWidget = new FeaturesPlugin_WidgetFilletMultiRadiuses(theParent, + theWorkshop, + theWidgetApi, + true); }else if (theType == "multiradiuscurv-panel") { - aWidget = new FeaturesPlugin_WidgetFilletMultiRadiuses(theParent, theWorkshop, theWidgetApi, false); + aWidget = new FeaturesPlugin_WidgetFilletMultiRadiuses(theParent, + theWorkshop, + theWidgetApi, + false); } - + return aWidget; } diff --git a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp b/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp index d2091a551..ca8cfa72b 100644 --- a/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp +++ b/src/FeaturesPlugin/FeaturesPlugin_WidgetFilletMultiRadiuses.cpp @@ -68,32 +68,32 @@ const char* MYFalse = "False"; class TextFieldDoubleValidator : public QDoubleValidator { public: - TextFieldDoubleValidator (QObject * parent = 0) : QDoubleValidator(parent) {} - TextFieldDoubleValidator (double bottom, double top, int decimals, QObject * parent) : - QDoubleValidator(bottom, top, decimals, parent) {} - - QValidator::State validate(QString & s, int & pos) const { - if (s.isEmpty() || s.startsWith("0.") || s == "0" ){//|| s.startsWith("-")) { - // allow empty field or minus sign - return QValidator::Intermediate; - } - // check length of decimal places - QChar point = locale().decimalPoint(); - if(s.indexOf(point) != -1) { - int lengthDecimals = s.length() - s.indexOf(point) - 1; - if (lengthDecimals > decimals()) { - return QValidator::Invalid; - } - } - - // check range of value - bool isNumber; - double value = locale().toDouble(s, &isNumber); - if (isNumber && bottom() <= value && value <= top()) { - return QValidator::Acceptable; - } - return QValidator::Invalid; - } + TextFieldDoubleValidator (QObject * parent = 0) : QDoubleValidator(parent) {} + TextFieldDoubleValidator (double bottom, double top, int decimals, QObject * parent) : + QDoubleValidator(bottom, top, decimals, parent) {} + + QValidator::State validate(QString & s, int & pos) const { + if (s.isEmpty() || s.startsWith("0.") || s == "0" ){ + // allow empty field or minus sign + return QValidator::Intermediate; + } + // check length of decimal places + QChar point = locale().decimalPoint(); + if(s.indexOf(point) != -1) { + int lengthDecimals = s.length() - s.indexOf(point) - 1; + if (lengthDecimals > decimals()) { + return QValidator::Invalid; + } + } + + // check range of value + bool isNumber; + double value = locale().toDouble(s, &isNumber); + if (isNumber && bottom() <= value && value <= top()) { + return QValidator::Acceptable; + } + return QValidator::Invalid; + } }; @@ -318,7 +318,6 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::storeValueCustom() aTablesAttr->setValue( getValue( aTblVal ), i, j); } } - if(myTypeMethodeBypoint && mySortList ){ AttributeSelectionListPtr aSelectionListAttr = @@ -368,7 +367,7 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::restoreValueCustom() else{ aTablesAttr = aData->tables(FeaturesPlugin_Fillet::VALUES_CURV_ID()); } - + if( aTablesAttr->rows() == 0 ) { aTablesAttr->setSize(2,2); @@ -441,8 +440,7 @@ bool FeaturesPlugin_WidgetFilletMultiRadiuses::restoreValueCustom() res = 0.0; myValuesSort[ res ] = std::make_pair (myfirstRowValue[0], findRadius( QString::number(res) )); res = 1.0; - std::cout << "res = restore = " << res << std::endl; - myValuesSort[ res ] = std::make_pair (myLastRowValue[0], findRadius( QString::number(res) )); + myValuesSort[ res ] = std::make_pair (myLastRowValue[0], findRadius( QString::number(res) )); aRows = myValuesSort.size(); }else{ @@ -521,8 +519,8 @@ void FeaturesPlugin_WidgetFilletMultiRadiuses::onAdd() { QModelIndex index = myDataTbl->currentIndex(); int i = index.row(); - if( i != -1 - && !(!myDataTbl->currentItem()->isSelected() && myDataTbl->rowCount() >2)) + if( i != -1 + && !(!myDataTbl->currentItem()->isSelected() && myDataTbl->rowCount() >2)) { myDataTbl->blockSignals(true); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Fillet.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Fillet.cpp index f1241dd36..1a4bd5bfd 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Fillet.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Fillet.cpp @@ -121,11 +121,11 @@ void GeomAlgoAPI_Fillet::build(const GeomShapePtr& theBaseSolid, } TColgp_Array1OfPnt2d array(1, theRadiuses.size()); - + int i = 1; std::list::const_iterator itCurv = theCurvCoord.begin(); std::list::const_iterator itRadius = theRadiuses.begin(); - + for( ; itCurv != theCurvCoord.end(); ++itCurv, ++itRadius ) { array.SetValue(i, gp_Pnt2d( (*itCurv) , (*itRadius))); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Fillet.h b/src/GeomAlgoAPI/GeomAlgoAPI_Fillet.h index 175a88717..2cfd2de9a 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Fillet.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Fillet.h @@ -49,7 +49,7 @@ public: const ListOfShape& theFilletEdges, const double theStartRadius, const double theEndRadius); - + /// Run fillet operation with variable radius. /// \param theBaseSolid a changing solid /// \param theFilletEdges list of edges the fillet is performed on @@ -77,8 +77,8 @@ private: /// \param theBaseSolid a changing solid /// \param theFilletEdges list of edges the fillet is performed on /// \param theCurvCoord the coordinate of a point defines a relative parameter on the edge - /// \param theRadiuses the corresponding value of the radius, and the radius evolves - // between the first and last vertices of the contour of index + /// \param theRadiuses the corresponding value of the radius, and the radius evolves + // between the first and last vertices of the contour of index void build(const GeomShapePtr& theBaseSolid, const ListOfShape& theFilletEdges, const std::list& theCurvCoord, 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_ */ -- 2.39.2