X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FExchangePlugin%2FExchangePlugin_ExportFeature.cpp;h=e81ae860df0abb368483973b515c6d042e66be8b;hb=f51f8ab55887ac6eff49fb9937a460abe1956517;hp=2a6bfebe4d9da5792d375ee7ac8f25601c5e68cb;hpb=50a8df0c6a66da8067b16155e5ae39f8f26a7ebc;p=modules%2Fshaper.git diff --git a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp index 2a6bfebe4..e81ae860d 100644 --- a/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp +++ b/src/ExchangePlugin/ExchangePlugin_ExportFeature.cpp @@ -27,6 +27,7 @@ #include #endif + #include #include @@ -34,6 +35,7 @@ #include #include #include +#include #include #include @@ -41,11 +43,14 @@ #include #include +#include + #include #include #include #include #include +#include #include #include #include @@ -96,9 +101,27 @@ void ExchangePlugin_ExportFeature::initAttributes() ModelAPI_AttributeString::typeId()); data()->addAttribute(ExchangePlugin_ExportFeature::XAO_SELECTION_LIST_ID(), ModelAPI_AttributeSelectionList::typeId()); + data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID(), + ModelAPI_AttributeString::typeId()); + data()->addAttribute(ExchangePlugin_ExportFeature::STL_OBJECT_SELECTED(), + ModelAPI_AttributeSelection::typeId()); + data()->addAttribute(ExchangePlugin_ExportFeature::STL_DEFLECTION_TYPE(), + ModelAPI_AttributeString::typeId()); + data()->addAttribute(ExchangePlugin_ExportFeature::STL_RELATIVE(), + ModelAPI_AttributeDouble::typeId()); + + double defelection = Config_PropManager::real("Visualization", "body_deflection"); + real(ExchangePlugin_ExportFeature::STL_RELATIVE())->setValue(defelection); + + data()->addAttribute(ExchangePlugin_ExportFeature::STL_ABSOLUTE(), + ModelAPI_AttributeDouble::typeId()); + data()->addAttribute(ExchangePlugin_ExportFeature::STL_FILE_TYPE(), + ModelAPI_AttributeString::typeId()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID()); + ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), + ExchangePlugin_ExportFeature::STL_FILE_PATH_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ExchangePlugin_ExportFeature::XAO_AUTHOR_ID()); ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), @@ -126,6 +149,11 @@ void ExchangePlugin_ExportFeature::attributeChanged(const std::string& theID) string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue( string(ExchangePlugin_ExportFeature::XAO_FILE_PATH_ID())->value()); } + else if (theID == STL_FILE_PATH_ID()) { + string(ExchangePlugin_ExportFeature::FILE_PATH_ID())->setValue( + string(ExchangePlugin_ExportFeature::STL_FILE_PATH_ID())->value()); + } + } /* @@ -168,6 +196,9 @@ void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName, if (aFormatName == "XAO") { exportXAO(theFileName); return; + }else if (aFormatName == "STL") { + exportSTL(theFileName); + return; } // make shape for export from selected shapes @@ -200,7 +231,7 @@ void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName, anError = "Unsupported format: " + aFormatName; } - if (!anError.empty()) { + if (!aResult || !anError.empty()) { setError("An error occurred while exporting " + theFileName + ": " + anError); return; } @@ -234,7 +265,6 @@ static bool isInResults(AttributeSelectionListPtr theSelection, { // collect all results into a cashed set if (theCashedResults.empty()) { - std::list aResults; std::list::const_iterator aRes = theResults.cbegin(); for(; aRes != theResults.cend(); aRes++) { if (theCashedResults.count(*aRes)) @@ -315,6 +345,48 @@ static bool isInResults(AttributeSelectionListPtr theSelection, return false; } +void ExchangePlugin_ExportFeature::exportSTL(const std::string& theFileName) +{ + // Get shape. + AttributeSelectionPtr aSelection = selection(STL_OBJECT_SELECTED()); + GeomShapePtr aShape = aSelection->value(); + if (!aShape.get()) { + aShape = aSelection->context()->shape(); + } + + // Get relative value and percent flag. + double aValue; + bool anIsRelative = false; + bool anIsASCII = false; + + if (string(STL_DEFLECTION_TYPE())->value() == STL_DEFLECTION_TYPE_RELATIVE()) { + aValue = real(STL_RELATIVE())->value(); + anIsRelative = true; + } else { + aValue = real(STL_ABSOLUTE())->value(); + } + + if (string(STL_FILE_TYPE())->value() == STL_FILE_TYPE_ASCII()) { + anIsASCII = true; + } + // Perform the export + std::string anError; + bool aResult = false; + + aResult = STLExport(theFileName, + aShape, + aValue, + anIsRelative, + anIsASCII, + anError); + + if (!aResult || !anError.empty()) { + setError("An error occurred while exporting " + theFileName + ": " + anError); + return; + } +} + + void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) { try { @@ -394,7 +466,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) if (aGeometryName.empty() && aResults.size() == 1) { // get the name from the first result ResultPtr aResultBody = *aResults.begin(); - aGeometryName = aResultBody->data()->name(); + aGeometryName = Locale::Convert::toString(aResultBody->data()->name()); } aXao.getGeometry()->setName(aGeometryName); @@ -429,7 +501,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) XAO::Dimension aGroupDimension = XAO::XaoUtils::stringToDimension(aDimensionString); XAO::Group* aXaoGroup = aXao.addGroup(aGroupDimension, - aResultGroup->data()->name()); + Locale::Convert::toString(aResultGroup->data()->name())); try { GeomAPI_ShapeExplorer aGroupResExplorer(aResultGroup->shape(), aSelType); @@ -448,7 +520,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) } catch (XAO::XAO_Exception& e) { // LCOV_EXCL_START std::string msg = "An error occurred while exporting group " + - aResultGroup->data()->name(); + Locale::Convert::toString(aResultGroup->data()->name()); msg += ".\n"; msg += e.what(); msg += "\n"; @@ -485,7 +557,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) XAO::Type aFieldType = XAO::XaoUtils::stringToFieldType(aTypeString); XAO::Field* aXaoField = aXao.addField(aFieldType, aFieldDimension, aTables->columns(), - aResultField->data()->name()); + Locale::Convert::toString(aResultField->data()->name())); try { @@ -511,8 +583,8 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) int anElementID = 0; if (!isWholePart) { // element index actually is the ID of the selection - AttributeSelectionPtr aSelection = aSelectionList->value(aRow - 1); - int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSelection->value()); + AttributeSelectionPtr aSel = aSelectionList->value(aRow - 1); + int aReferenceID = GeomAlgoAPI_CompoundBuilder::id(aShape, aSel->value()); if (aReferenceID == 0) // selected value does not found in the exported shape continue; @@ -546,7 +618,7 @@ void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName) } catch (XAO::XAO_Exception& e) { // LCOV_EXCL_START std::string msg = "An error occurred while exporting field " + - aResultField->data()->name(); + Locale::Convert::toString(aResultField->data()->name()); msg += ".\n"; msg += e.what(); msg += "\n";