#include <ExchangePlugin_ExportFeature.h>
//#include <GeomAlgoAPI_BREPExport.h>
//#include <GeomAlgoAPI_STEPExport.h>
-//#include <GeomAlgoAPI_IGESExport.h>
+#include <GeomAlgoAPI_IGESExport.h>
-#include <GeomAPI_Shape.h>
#include <Config_Common.h>
#include <Config_PropManager.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+
+#include <GeomAPI_Shape.h>
+
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <ModelAPI_Data.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Object.h>
void ExchangePlugin_ExportFeature::initAttributes()
{
data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
+ data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
}
/*
AttributeStringPtr aFilePathAttr = std::dynamic_pointer_cast<ModelAPI_AttributeString>(
data()->attribute(ExchangePlugin_ExportFeature::FILE_PATH_ID()));
std::string aFilePath = aFilePathAttr->value();
- if(aFilePath.empty())
+ if (aFilePath.empty())
return;
- exportFile(aFilePath);
+
+ AttributeSelectionListPtr aSelectionListAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(
+ data()->attribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID()));
+
+ std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
+ for ( int i = 0, aSize = aSelectionListAttr->size(); i < aSize; ++i ) {
+ std::shared_ptr<ModelAPI_AttributeSelection> anSelectionAttr = aSelectionListAttr->value(i);
+ aShapes.push_back(anSelectionAttr->value());
+ }
+ std::shared_ptr<GeomAPI_Shape> aShape =
+ GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+
+ exportFile(aFilePath, aShape);
}
-bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName)
+bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
+ std::shared_ptr<GeomAPI_Shape> theShape)
{
// retrieve the file and plugin library names
- TCollection_AsciiString aFileName (theFileName.c_str());
+ TCollection_AsciiString aFileName(theFileName.c_str());
OSD_Path aPath(aFileName);
TCollection_AsciiString aFormatName = aPath.Extension();
// ".brep" -> "BREP", TCollection_AsciiString are numbered from 1
TCollection_AsciiString anError;
TDF_Label anUnknownLabel = TDF_Label();
- TopoDS_Shape aShape;
-// if (aFormatName == "BREP") {
+ TopoDS_Shape aShape(theShape->impl<TopoDS_Shape>());
+ bool aResult = true;
+ if (aFormatName == "BREP") {
// aShape = BREPExport::Export(aFileName, aFormatName, anError, anUnknownLabel);
-// } else if (aFormatName == "STEP" || aFormatName == "STP") {
+ } else if (aFormatName == "STEP" || aFormatName == "STP") {
// aShape = STEPExport::Export(aFileName, aFormatName, anError, anUnknownLabel);
-// } else if (aFormatName == "IGES") {
-// aShape = IGESExport::Export(aFileName, aFormatName, anError, anUnknownLabel);
-// }
-// // Check if shape is valid
-// if ( aShape.IsNull() ) {
-// const static std::string aShapeError =
-// "An error occurred while exporting " + theFileName + ": " + anError.ToCString();
-// setError(aShapeError);
-// return false;
-// }
-//
-// // Pass the results into the model
-// std::string anObjectName = aPath.Name().ToCString();
-// data()->setName(anObjectName);
-// std::shared_ptr<ModelAPI_ResultBody> aResultBody = document()->createBody(data());
-// std::shared_ptr<GeomAPI_Shape> aGeomShape(new GeomAPI_Shape);
-// aGeomShape->setImpl(new TopoDS_Shape(aShape));
-//
-// //LoadNamingDS of the exported shape
-// loadNamingDS(aGeomShape, aResultBody);
-//
-// setResult(aResultBody);
+ } else if (aFormatName == "IGES") {
+ aResult = IGESExport::Export(aFileName, aFormatName, aShape, anError, anUnknownLabel);
+ }
- return true;
-}
+ if ( !aResult ) {
+ const static std::string aShapeError =
+ "An error occurred while exporting " + theFileName + ": " + anError.ToCString();
+ setError(aShapeError);
+ return false;
+ }
-//============================================================================
-void ExchangePlugin_ExportFeature::loadNamingDS(
- std::shared_ptr<GeomAPI_Shape> theGeomShape,
- std::shared_ptr<ModelAPI_ResultBody> theResultBody)
-{
- //load result
- theResultBody->store(theGeomShape);
-
- int aTag(1);
- std::string aNameMS = "Shape";
- theResultBody->loadFirstLevel(theGeomShape, aNameMS, aTag);
- //std::string aNameDE = "DiscEdges";
- //theResultBody->loadDisconnectedEdges(theGeomShape, aNameDE, aTag);
- //std::string aNameDV = "DiscVertexes";
- //theResultBody->loadDisconnectedVertexes(theGeomShape, aNameDV, aTag);
+ return true;
}
class ExchangePlugin_ExportFeature : public ModelAPI_Feature
{
public:
- /// Extrusion kind
inline static const std::string& ID()
{
static const std::string MY_EXPORT_ID("Export");
return MY_EXPORT_ID;
}
- /// attribute name of referenced face
+ /// attribute name of file path
inline static const std::string& FILE_PATH_ID()
{
static const std::string MY_FILE_PATH_ID("export_file_selector");
return MY_FILE_PATH_ID;
}
+ /// attribute name of selection list
+ inline static const std::string& SELECTION_LIST_ID()
+ {
+ static const std::string MY_SELECTION_LIST_ID("selection_list");
+ return MY_SELECTION_LIST_ID;
+ }
/// default constructor
EXCHANGEPLUGIN_EXPORT ExchangePlugin_ExportFeature();
/// default destructor
protected:
/// Performs the export of the file
- EXCHANGEPLUGIN_EXPORT bool exportFile(const std::string& theFileName);
-
-private:
- /// Loads Naming data structure to the document
- void loadNamingDS(std::shared_ptr<GeomAPI_Shape> theGeomShape,
- std::shared_ptr<ModelAPI_ResultBody> theResultBody);
+ EXCHANGEPLUGIN_EXPORT bool exportFile(const std::string& theFileName,
+ std::shared_ptr<GeomAPI_Shape> theShape);
};
#endif /* EXPORT_EXPORTFEATURE_H_ */
bool ExchangePlugin_ImportFeature::importFile(const std::string& theFileName)
{
// retrieve the file and plugin library names
- TCollection_AsciiString aFileName (theFileName.c_str());
+ TCollection_AsciiString aFileName(theFileName.c_str());
OSD_Path aPath(aFileName);
TCollection_AsciiString aFormatName = aPath.Extension();
// ".brep" -> "BREP", TCollection_AsciiString are numbered from 1
//============================================================================
void ExchangePlugin_ImportFeature::loadNamingDS(
- std::shared_ptr<GeomAPI_Shape> theGeomShape,
- std::shared_ptr<ModelAPI_ResultBody> theResultBody)
-{
+ std::shared_ptr<GeomAPI_Shape> theGeomShape,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBody)
+{
//load result
theResultBody->store(theGeomShape);
-
+
int aTag(1);
std::string aNameMS = "Shape";
theResultBody->loadFirstLevel(theGeomShape, aNameMS, aTag);
}
protected:
- /// POerforms the import of the file
+ /// Performs the import of the file
EXCHANGEPLUGIN_EXPORT bool importFile(const std::string& theFileName);
private:
ModelAPI_ValidatorsFactory* aFactory = aSession->validators();
aFactory->registerValidator("ExchangePlugin_ImportFormat",
new ExchangePlugin_ImportFormatValidator);
+ aFactory->registerValidator("ExchangePlugin_ExportFormat",
+ new ExchangePlugin_ExportFormatValidator);
// register construction properties
//Config_PropManager::registerProp("Visualization", "import_feature_color", "Imported feature color",
#include <sstream>
#include <algorithm>
-bool ExchangePlugin_ImportFormatValidator::parseFormats(const std::list<std::string>& theArguments,
- std::list<std::string>& outFormats)
+bool ExchangePlugin_FormatValidator::parseFormats(const std::list<std::string>& theArguments,
+ std::list<std::string>& outFormats)
{
std::list<std::string>::const_iterator it = theArguments.begin();
bool result = true;
return result;
}
-bool ExchangePlugin_ImportFormatValidator::isValid(const AttributePtr& theAttribute,
- const std::list<std::string>& theArguments) const
+bool ExchangePlugin_FormatValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments) const
{
- SessionPtr aMgr = ModelAPI_Session::get();
- ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
- if (theAttribute->isInitialized()) {
- const AttributeStringPtr aStrAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
- if(!aStrAttr)
- return false;
- std::string aFileName = aStrAttr->value();
- if (!aFileName.empty()) {
- std::list<std::string> aFormats;
- ExchangePlugin_ImportFormatValidator::parseFormats(theArguments, aFormats);
- std::list<std::string>::const_iterator itFormats = aFormats.begin();
- size_t aFileNameLen = aFileName.length();
- std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper);
- // Is file name ends with the format
- for (; itFormats != aFormats.end(); ++itFormats) {
- size_t aFormatBeginPos = aFileNameLen - (*itFormats).length();
- if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) {
- return true;
- }
- }
+ if (!theAttribute->isInitialized())
+ return false;
+
+ const AttributeStringPtr aStrAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
+ if (!aStrAttr)
+ return false;
+
+ std::string aFileName = aStrAttr->value();
+ if (aFileName.empty())
+ return false;
+
+ std::list<std::string> aFormats;
+ ExchangePlugin_FormatValidator::parseFormats(theArguments, aFormats);
+ std::list<std::string>::const_iterator itFormats = aFormats.begin();
+ size_t aFileNameLen = aFileName.length();
+ std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper);
+ // Is file name ends with the format
+ for (; itFormats != aFormats.end(); ++itFormats) {
+ size_t aFormatBeginPos = aFileNameLen - (*itFormats).length();
+ if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) {
+ return true;
}
}
return false;
}
-
* about which formats are supported and the extension of the associated files.
* This validator filters out files that are out of this description.
*/
-class ExchangePlugin_ImportFormatValidator : public ModelAPI_AttributeValidator
+class ExchangePlugin_FormatValidator : public ModelAPI_AttributeValidator
{
/**
- * Parses input arguments "BREP:BREPImport", "STEP:STEPImport"
- * into list of file formats "BREP","STEP"
+ * Parses input arguments "BREP:BREPImport", "STEP|STP:STEPImport"
+ * into list of file formats "BREP","STEP","STP"
* and list of corresponding plugins: "BREPImport", "STEPImport"
*/
static bool parseFormats(const std::list<std::string>& theArguments,
*/
virtual bool isValid(const AttributePtr& theAttribute,
const std::list<std::string>& theArguments) const;
+};
+class ExchangePlugin_ImportFormatValidator : public ExchangePlugin_FormatValidator
+{
+};
+
+class ExchangePlugin_ExportFormatValidator : public ExchangePlugin_FormatValidator
+{
};
</file_selector>
</feature>
<feature id="Export" title="Export" tooltip="Export to file" icon=":icons/export.png">
- <file_selector id="export_file_selector" title="Export file" path="">
- <validator id="ExchangePlugin_ExportFormat" parameters="BREgi tP:BREPExport,STEP|STP:STEPExport,IGES:IGESExport" />
+ <file_selector id="export_file_selector" type="save" title="Export file" path="">
+ <validator id="ExchangePlugin_ExportFormat" parameters="BREP:BREPExport,STEP|STP:STEPExport,IGES:IGESExport" />
</file_selector>
+ <multi_selector id="selection_list" tooltip="Select a set of objects" type_choice="Vertices Edges Faces Solids" />
</feature>
</group>
</workbench>
GeomAlgoAPI_BREPImport.h
GeomAlgoAPI_STEPImport.h
GeomAlgoAPI_IGESImport.h
+ GeomAlgoAPI_IGESExport.h
)
SET(PROJECT_SOURCES
GeomAlgoAPI_BREPImport.cpp
GeomAlgoAPI_STEPImport.cpp
GeomAlgoAPI_IGESImport.cpp
+ GeomAlgoAPI_IGESExport.cpp
)
SET(PROJECT_LIBRARIES
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+#include <GeomAlgoAPI_IGESExport.h>
+
+//// KERNEL includes
+//#include <utilities.h>
+//#include <Basics_Utils.hxx>
+
+// OOCT includes
+#include <IGESControl_Controller.hxx>
+#include <IGESControl_Writer.hxx>
+#include <Interface_Static.hxx>
+
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Iterator.hxx>
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+/*!
+ * KindOfBRep
+ * \return 0 if theShape contains only simple entities (wires, edges and vertices),
+ * 1 if theShape contains only complex entities (shells, solids and compsolids)
+ * 2 if theShape contains only indifferent entities (faces)
+ * -1 if theShape contains both simple and complex entities (and in this case it
+ * cannot be saved without any loss neither in BRepMode == 0 nor in BRepMode == 1)
+ */
+//=============================================================================
+int KindOfBRep (const TopoDS_Shape& theShape)
+{
+ int aKind = 2;
+
+ switch (theShape.ShapeType())
+ {
+ case TopAbs_COMPOUND:
+ {
+ bool isSimple = false;
+ bool isComplex = false;
+ TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
+ for (; anIt.More(); anIt.Next()) {
+ TopoDS_Shape aS = anIt.Value();
+ int aKindSub = KindOfBRep(aS);
+ if (aKindSub == 0)
+ isSimple = true;
+ else if (aKindSub == 1)
+ isComplex = true;
+ else if (aKindSub == -1) {
+ return -1; // heterogeneous
+ }
+ }
+ if (isSimple && isComplex)
+ aKind = -1; // heterogeneous
+ else if (isSimple)
+ aKind = 0;
+ else if (isComplex)
+ aKind = 1;
+ }
+ break;
+ case TopAbs_COMPSOLID:
+ case TopAbs_SOLID:
+ case TopAbs_SHELL:
+ aKind = 1;
+ break;
+ case TopAbs_WIRE:
+ case TopAbs_EDGE:
+ case TopAbs_VERTEX:
+ aKind = 0;
+ break;
+ default:
+ aKind = 2;
+ }
+
+ return aKind;
+}
+
+//=============================================================================
+//extern "C" {
+namespace IGESExport {
+
+bool Export(const TCollection_AsciiString& theFileName,
+ const TCollection_AsciiString&,
+ const TopoDS_Shape& theShape,
+ TCollection_AsciiString& theError, const TDF_Label&)
+{
+ //TODO(spo): pass version as argument of the function
+ TCollection_AsciiString aVersion = "5.3";
+ // define, whether to write only faces (5.1 IGES format)
+ // or shells and solids also (5.3 IGES format)
+ int aBrepMode = 0;
+ if( aVersion.IsEqual( "5.3" ) )
+ aBrepMode = 1;
+
+ #ifdef _DEBUG
+ std::cout << "Export IGES into file " << theFileName.ToCString() << std::endl;
+ #endif
+
+ // Mantis issue 0021350: check being exported shape, as some stand-alone
+ // entities (edges, wires and vertices) cannot be saved in BRepMode
+ if( aBrepMode == 1 ) {
+ int aKind = KindOfBRep( theShape );
+ if( aKind == -1 ) {
+ theError = "EXPORT_IGES_HETEROGENEOUS_COMPOUND";
+ return false;
+ } else if( aKind == 2 )
+ aBrepMode = 1;
+ else
+ aBrepMode = aKind;
+ }
+
+// // Set "C" numeric locale to save numbers correctly
+// Kernel_Utils::Localizer loc;
+
+ // initialize writer
+ IGESControl_Controller::Init();
+ IGESControl_Writer ICW( "M", aBrepMode ); // export explicitly in meters
+ Interface_Static::SetCVal( "xstep.cascade.unit", "M" );
+
+ // 09.03.2010 skl for bug 0020726
+ // change default value "Average" to "Max"
+ Interface_Static::SetCVal( "write.precision.mode", "Max" );
+
+ // perform shape writing
+ if( ICW.AddShape( theShape ) ) {
+ ICW.ComputeModel();
+ return (bool)ICW.Write( theFileName.ToCString() );
+ }
+ return false;
+}
+
+}
+
+//}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+/*
+ * GEOMALGOAPI_IGESExport.h
+ *
+ * Created on: Dec 24, 2014
+ * Author: sbh
+ */
+
+#ifndef GEOMALGOAPI_IGESEXPORT_H_
+#define GEOMALGOAPI_IGESEXPORT_H_
+
+#include <GeomAlgoAPI.h>
+
+#include <TCollection_AsciiString.hxx>
+#include <TopoDS_Shape.hxx>
+#include <TDF_Label.hxx>
+
+namespace IGESExport {
+
+/// Implementation of the import IGES files algorithms
+GEOMALGOAPI_EXPORT
+bool Export(const TCollection_AsciiString& theFileName,
+ const TCollection_AsciiString& theFormatName,
+ const TopoDS_Shape& theShape,
+ TCollection_AsciiString& theError, const TDF_Label&);
+
+}
+
+#endif /* GEOMALGOAPI_IGESEXPORT_H_ */
std::cout << "Import IGES from file " << theFileName << std::endl;
#endif
TopoDS_Shape aResShape;
-
-// bool anIsIgnoreUnits = false;
-
IGESControl_Reader aReader;
try {
IFSelect_ReturnStatus status = aReader.ReadFile( theFileName.ToCString() );
if (status == IFSelect_RetDone) {
-// if( anIsIgnoreUnits ) {
-// // need re-scale a model, set UnitFlag to 'meter'
-// Handle(IGESData_IGESModel) aModel =
-// Handle(IGESData_IGESModel)::DownCast( aReader.Model() );
-// if( !aModel.IsNull() ) {
-// IGESData_GlobalSection aGS = aModel->GlobalSection();
-// aGS.SetUnitFlag(6);
-// aModel->SetGlobalSection(aGS);
-// }
-// }
-
#ifdef _DEBUG
std::cout << "ImportIGES : all Geometry Transfer" << std::endl;
#endif
default:
theError = "Wrong format of the imported file. Can't import file.";
break;
- }
+ }
aResShape.Nullify();
}
}
/*
* GEOMALGOAPI_IGESImport.h
*
- * Created on: Dec 24, 2014
- * Author: sbh
+ * Created on: May 14, 2015
+ * Author: spo
*/
#ifndef GEOMALGOAPI_IGESIMPORT_H_
: ModuleBase_ModelWidget(theParent, theData, theParentId)
{
myTitle = QString::fromStdString(theData->getProperty("title"));
+ myType = (theData->getProperty("type") == "save") ? WFS_SAVE : WFS_OPEN;
myDefaultPath = QString::fromStdString(theData->getProperty("path"));
QGridLayout* aMainLay = new QGridLayout(this);
bool ModuleBase_WidgetFileSelector::storeValueCustom() const
{
// A rare case when plugin was not loaded.
- if(!myFeature)
+ if (!myFeature)
return false;
DataPtr aData = myFeature->data();
AttributeStringPtr aStringAttr = aData->string(attributeID());
bool ModuleBase_WidgetFileSelector::restoreValue()
{
// A rare case when plugin was not loaded.
- if(!myFeature)
+ if (!myFeature)
return false;
DataPtr aData = myFeature->data();
AttributeStringPtr aStringAttr = aData->string(attributeID());
bool ModuleBase_WidgetFileSelector::isCurrentPathValid()
{
- QFileInfo aFile (myPathField->text());
+ QFileInfo aFile(myPathField->text());
return aFile.exists();
}
-
void ModuleBase_WidgetFileSelector::onPathSelectionBtn()
{
- QString aFilter = formatsString();
- QString aFileName = QFileDialog::getOpenFileName(this, myTitle, myDefaultPath, aFilter);
+ QString aFilter = filterString();
+ QString aFileName = (myType == WFS_SAVE)
+ ? QFileDialog::getSaveFileName(this, myTitle, myDefaultPath, aFilter)
+ : QFileDialog::getOpenFileName(this, myTitle, myDefaultPath, aFilter);
if (!aFileName.isEmpty()) {
myPathField->setText(aFileName);
}
void ModuleBase_WidgetFileSelector::onPathChanged()
{
- if(!isCurrentPathValid())
+ if (myType == WFS_OPEN && !isCurrentPathValid())
return;
storeValue();
emit valuesChanged();
}
-QString ModuleBase_WidgetFileSelector::formatsString() const
+QString ModuleBase_WidgetFileSelector::filterString() const
{
QStringList aResult;
QStringList aValidatorFormats = getValidatorFormats();
std::list<ModelAPI_Validator*> allValidators;
std::list<std::list<std::string> > allArguments;
aFactory->validators(myFeature->getKind(), myAttributeID, allValidators, allArguments);
- //TODO(sbh): extract as separate method
- if(allArguments.empty())
- return QStringList();
+ QStringList aResult;
std::list<std::string> anArgumentList = allArguments.front();
std::list<std::string>::const_iterator it = anArgumentList.begin();
- QStringList aResult;
for (; it != anArgumentList.end(); ++it) {
- std::string anArg = *it;
- int aSepPos = anArg.find(":");
- if (aSepPos == std::string::npos) {
- continue;
- }
- QString aFormat = QString::fromStdString(anArg.substr(0, aSepPos));
- aFormat = aFormat.toUpper();
- aResult.append(aFormat);
+ QString aFormat = getFormat(*it);
+ if (!aFormat.isNull())
+ aResult << aFormat;
}
return aResult;
}
+
+QString ModuleBase_WidgetFileSelector::getFormat( const std::string& theArgument ) const
+{
+ QString anArgument = QString::fromStdString(theArgument);
+ if (!anArgument.contains(":"))
+ return QString();
+ return anArgument.section(":", 0, 0).toUpper();
+}
+
* \code
* <file_selector
* id="import_file_selector"
+* type="open"
* title="Import file"
* path="">
* <validator id="ExchangePlugin_ImportFormat" parameters="BREP:BREPImport,STEP:STEPImport" />
protected:
/// Returns string containing formats
- QString formatsString() const;
+ QString filterString() const;
- /// Return list of validator formats
+ /// Returns list of validator formats
QStringList getValidatorFormats() const;
+ /// Returns a format received from theArgument
+ QString getFormat( const std::string& theArgument ) const;
+
private:
/// A control for path input
QLineEdit* myPathField;
/// A title of open file dialog box
QString myTitle;
+ /// A title of open file dialog box
+ enum { WFS_OPEN, WFS_SAVE } myType;
+
/// Default path
QString myDefaultPath;
};