)
SET(XML_RESOURCES
+ export_widget.xml
plugin-Exchange.xml
)
#include <ExchangePlugin_ExportFeature.h>
-#include <ExchangePlugin_Tools.h>
+#include <algorithm>
+#include <iterator>
+#include <string>
+#ifdef _DEBUG
+#include <iostream>
+#include <ostream>
+#endif
+
+#include <Config_Common.h>
+#include <Config_PropManager.h>
#include <GeomAlgoAPI_BREPExport.h>
#include <GeomAlgoAPI_CompoundBuilder.h>
#include <GeomAlgoAPI_IGESExport.h>
#include <GeomAlgoAPI_STEPExport.h>
#include <GeomAlgoAPI_Tools.h>
-
-#include <Config_Common.h>
-#include <Config_PropManager.h>
+#include <GeomAlgoAPI_XAOExport.h>
#include <GeomAPI_Shape.h>
#include <ModelAPI_Document.h>
#include <ModelAPI_Object.h>
#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_Session.h>
+#include <ModelAPI_Validator.h>
-#include <algorithm>
-#include <iterator>
-#include <string>
-#ifdef _DEBUG
-#include <iostream>
-#include <ostream>
-#endif
+#include <XAO_Xao.hxx>
+
+#include <ExchangePlugin_Tools.h>
ExchangePlugin_ExportFeature::ExchangePlugin_ExportFeature()
{
// TODO Auto-generated destructor stub
}
-/*
- * Returns the unique kind of a feature
- */
-const std::string& ExchangePlugin_ExportFeature::getKind()
-{
- return ExchangePlugin_ExportFeature::ID();
-}
-
/*
* Request for initialization of data model of the feature: adding all attributes
*/
void ExchangePlugin_ExportFeature::initAttributes()
{
+ data()->addAttribute(ExchangePlugin_ExportFeature::EXPORT_TYPE_ID(), ModelAPI_AttributeString::typeId());
data()->addAttribute(ExchangePlugin_ExportFeature::FILE_PATH_ID(), ModelAPI_AttributeString::typeId());
data()->addAttribute(ExchangePlugin_ExportFeature::FILE_FORMAT_ID(), ModelAPI_AttributeString::typeId());
data()->addAttribute(ExchangePlugin_ExportFeature::SELECTION_LIST_ID(), ModelAPI_AttributeSelectionList::typeId());
+ data()->addAttribute(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID(), ModelAPI_AttributeString::typeId());
+
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), ExchangePlugin_ExportFeature::XAO_AUTHOR_ID());
}
/*
if (aCurShape.get() != NULL)
aShapes.push_back(aCurShape);
}
- std::shared_ptr<GeomAPI_Shape> aShape =
- GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+ std::shared_ptr<GeomAPI_Shape> aShape = aShapes.size() == 1
+ ? *aShapes.begin()
+ : GeomAlgoAPI_CompoundBuilder::compound(aShapes);
exportFile(aFilePath, aFormat, aShape);
}
-bool ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
+void ExchangePlugin_ExportFeature::exportFile(const std::string& theFileName,
const std::string& theFormat,
std::shared_ptr<GeomAPI_Shape> theShape)
{
- // retrieve the file and plugin library names
std::string aFormatName = theFormat;
- if (theFormat.empty()) { // look at extension
+ if (aFormatName.empty()) { // get default format for the extension
// ".brep" -> "BREP"
std::string anExtension = GeomAlgoAPI_Tools::File_Tools::extension(theFileName);
if (anExtension == "BREP" || anExtension == "BRP") {
aFormatName = "STEP";
} else if (anExtension == "IGES" || anExtension == "IGS") {
aFormatName = "IGES-5.1";
+ } else if (anExtension == "XAO") {
+ aFormatName = "XAO";
} else {
aFormatName = anExtension;
}
}
+ if (aFormatName == "XAO") {
+ exportXAO(theFileName, theShape);
+ return;
+ }
+
// Perform the export
std::string anError;
bool aResult = false;
} else if (aFormatName.substr(0, 4) == "IGES") {
aResult = IGESExport(theFileName, aFormatName, theShape, anError);
} else {
- anError = "Unsupported format " + aFormatName;
+ anError = "Unsupported format: " + aFormatName;
}
- if (!aResult) {
- std::string aShapeError =
- "An error occurred while exporting " + theFileName + ": " + anError;
- setError(aShapeError);
- return false;
+ if (!anError.empty()) {
+ setError("An error occurred while exporting " + theFileName + ": " + anError);
+ return;
}
+}
+
+void ExchangePlugin_ExportFeature::exportXAO(const std::string& theFileName,
+ std::shared_ptr<GeomAPI_Shape> theShape)
+{
+ std::string anAuthor = string(ExchangePlugin_ExportFeature::XAO_AUTHOR_ID())->value();
+
+ XAO::Xao aXao(anAuthor, "1.0");
- return true;
+ std::string anError;
+ XAOExport(theFileName, theShape, &aXao, anError);
+
+ if (!anError.empty()) {
+ setError("An error occurred while exporting " + theFileName + ": " + anError);
+ return;
+ }
}
+
static const std::string MY_EXPORT_ID("Export");
return MY_EXPORT_ID;
}
+ /// attribute name for file format
+ inline static const std::string& EXPORT_TYPE_ID()
+ {
+ static const std::string MY_EXPORT_TYPE_ID("ExportType");
+ return MY_EXPORT_TYPE_ID;
+ }
/// attribute name of file path
inline static const std::string& FILE_PATH_ID()
{
static const std::string MY_SELECTION_LIST_ID("selection_list");
return MY_SELECTION_LIST_ID;
}
+ /// attribute name of author for XAO format
+ inline static const std::string& XAO_AUTHOR_ID()
+ {
+ static const std::string MY_XAO_AUTHOR_ID("xao_author");
+ return MY_XAO_AUTHOR_ID;
+ }
/// Default constructor
EXCHANGEPLUGIN_EXPORT ExchangePlugin_ExportFeature();
/// Default destructor
EXCHANGEPLUGIN_EXPORT virtual ~ExchangePlugin_ExportFeature();
+ /// Returns the unique kind of a feature
+ EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ return ExchangePlugin_ExportFeature::ID();
+ }
+
/// Request for initialization of data model of the feature: adding all attributes
EXCHANGEPLUGIN_EXPORT virtual void initAttributes();
- /// Returns the unique kind of a feature
- EXCHANGEPLUGIN_EXPORT virtual const std::string& getKind();
-
/// Computes or recomputes the results
EXCHANGEPLUGIN_EXPORT virtual void execute();
EXCHANGEPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
protected:
- /// Performs the export of the file
- EXCHANGEPLUGIN_EXPORT bool exportFile(const std::string& theFileName,
+ /// Performs export of the file
+ EXCHANGEPLUGIN_EXPORT void exportFile(const std::string& theFileName,
const std::string& theFormat,
std::shared_ptr<GeomAPI_Shape> theShape);
+
+ /// Performs export to XAO file
+ EXCHANGEPLUGIN_EXPORT void exportXAO(const std::string& theFileName,
+ std::shared_ptr<GeomAPI_Shape> theShape);
};
#endif /* EXPORT_EXPORTFEATURE_H_ */
#include <GeomAlgoAPI_BREPImport.h>
#include <GeomAlgoAPI_IGESImport.h>
#include <GeomAlgoAPI_STEPImport.h>
-#include <GeomAlgoAPI_XAOImport.h>
#include <GeomAlgoAPI_Tools.h>
+#include <GeomAlgoAPI_XAOImport.h>
#include <GeomAPI_Shape.h>
} else if (anExtension == "IGES" || anExtension == "IGS") {
aGeomShape = IGESImport(theFileName, anExtension, anError);
} else {
- anError = "Cann't read files with extension: " + anExtension;
+ anError = "Unsupported format: " + anExtension;
}
// Check if shape is valid
}
XAO::Geometry* aXaoGeometry = aXao.getGeometry();
- data()->setName(aXaoGeometry->getName());
- std::shared_ptr<ModelAPI_ResultBody> aResultBody = createResultBody(aGeomShape);
- aResultBody->data()->setName(aXaoGeometry->getName());
+ // use the geometry name or the file name for the feature
+ std::string aBodyName = aXaoGeometry->getName().empty()
+ ? GeomAlgoAPI_Tools::File_Tools::name(theFileName)
+ : aXaoGeometry->getName();
+ data()->setName(aBodyName);
+
+ ResultBodyPtr aResultBody = createResultBody(aGeomShape);
setResult(aResultBody);
// Process groups
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<source>
+ <switch id="ExportType">
+ <case id="Regular" title="BREP, STEP, IGES">
+ <export_file_selector id="file_path"
+ type="save"
+ title="Export file"
+ path="">
+ <validator id="ExchangePlugin_ExportFormat"
+ parameters="BREP|BRP:BREP,STEP|STP:STEP,IGES|IGS:IGES-5.1,IGES|IGS:IGES-5.3" />
+ </export_file_selector>
+ </case>
+ <case id="XAO" title="XAO">
+ <export_file_selector id="file_path"
+ type="save"
+ title="Export file"
+ path="">
+ <validator id="ExchangePlugin_ExportFormat"
+ parameters="XAO:XAO" />
+ </export_file_selector>
+ <stringvalue id="xao_author"
+ label="Author"
+ placeholder="Please input the author">
+ </stringvalue>
+ </case>
+ </switch>
+ <multi_selector id="selection_list"
+ tooltip="Select a set of objects"
+ type_choice="Vertices Edges Faces Solids Objects">
+ <validator id="GeomValidators_Finite"/>
+ </multi_selector>
+</source>
<plugin>
<workbench id="Part">
<group id="Exchange">
- <feature id="Import" title="Import" tooltip="Import a file" icon=":icons/import.png" document="Part">
+ <feature
+ id="Import"
+ title="Import"
+ tooltip="Import a file"
+ icon=":icons/import.png"
+ document="Part">
<file_selector id="file_path" title="Import file" path="">
<validator id="ExchangePlugin_ImportFormat" parameters="BREP|BRP:BREP,STEP|STP:STEP,IGES|IGS:IGES,XAO:XAO" />
</file_selector>
</feature>
- <feature id="Export" title="Export" tooltip="Export to file" icon=":icons/export.png">
- <export_file_selector id="file_path" type="save" title="Export file" path="">
- <validator id="ExchangePlugin_ExportFormat" parameters="BREP|BRP:BREP,STEP|STP:STEP,IGES|IGS:IGES-5.1,IGES|IGS:IGES-5.3,XAO:XAO" />
- </export_file_selector>
- <multi_selector id="selection_list" tooltip="Select a set of objects" type_choice="Vertices Edges Faces Solids Objects">
- <validator id="GeomValidators_Finite"/>
- </multi_selector>
+ <feature
+ id="Export"
+ title="Export"
+ tooltip="Export to file"
+ icon=":icons/export.png">
+ <source path="export_widget.xml" />
</feature>
</group>
</workbench>
-</plugin>
\ No newline at end of file
+</plugin>
GeomAlgoAPI_ShapeTools.h
GeomAlgoAPI_Partition.h
GeomAlgoAPI_PaveFiller.h
+ GeomAlgoAPI_XAOExport.h
GeomAlgoAPI_XAOImport.h
)
GeomAlgoAPI_ShapeTools.cpp
GeomAlgoAPI_Partition.cpp
GeomAlgoAPI_PaveFiller.cpp
+ GeomAlgoAPI_XAOExport.cpp
GeomAlgoAPI_XAOImport.cpp
)
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GEOMALGOAPI_XAOExport.cpp
+// Created: Nov 27, 2015
+// Author: Sergey POKHODENKO
+
+#include <GeomAlgoAPI_XAOExport.h>
+
+#include "GeomAlgoAPI_Tools.h"
+
+#include <TopoDS_Shape.hxx>
+
+#include <XAO_XaoExporter.hxx>
+#include <XAO_BrepGeometry.hxx>
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+bool XAOExport(const std::string& theFileName,
+ const std::shared_ptr<GeomAPI_Shape>& theShape,
+ XAO::Xao* theXao,
+ std::string& theError)
+{
+ #ifdef _DEBUG
+ std::cout << "Export XAO into file " << theFileName << std::endl;
+ #endif
+
+ if (theFileName.empty() || !theShape.get() || !theXao) {
+ theError = "An invalid argument.";
+ return false;
+ }
+
+ TopoDS_Shape aShape = theShape->impl<TopoDS_Shape>();
+ try {
+ XAO::BrepGeometry* aGeometry = new XAO::BrepGeometry;
+ theXao->setGeometry(aGeometry);
+ aGeometry->setTopoDS_Shape(aShape);
+ XAO::XaoExporter::saveToFile(theXao, theFileName);
+ } catch (XAO::XAO_Exception& e) {
+ theError = e.what();
+ return false;
+ }
+ return true;
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: GEOMALGOAPI_XAOExport.h
+// Created: Nov 27, 2015
+// Author: Sergey POKHODENKO
+
+#ifndef GEOMALGOAPI_XAOEXPORT_H_
+#define GEOMALGOAPI_XAOEXPORT_H_
+
+#include <GeomAlgoAPI.h>
+
+#include <string>
+
+#include <GeomAPI_Shape.h>
+
+namespace XAO {
+class Xao;
+} // namespace XAO
+
+/// Implementation of the export XAO files algorithms
+GEOMALGOAPI_EXPORT
+bool XAOExport(const std::string& theFileName,
+ const std::shared_ptr<GeomAPI_Shape>& theShape,
+ XAO::Xao* theXao,
+ std::string& theError);
+
+#endif /* GEOMALGOAPI_XAOEXPORT_H_ */
#include <GeomAlgoAPI_XAOImport.h>
-#include <cassert>
-
#include <TopoDS_Shape.hxx>
#include <XAO_XaoExporter.hxx>
std::string& theError,
XAO::Xao* theXao)
{
- assert(theXao);
-
#ifdef _DEBUG
std::cout << "Import XAO from file " << theFileName << std::endl;
#endif
+ if (theFileName.empty() || !theXao) {
+ theError = "An invalid argument.";
+ return std::shared_ptr<GeomAPI_Shape>();
+ }
+
TopoDS_Shape aShape;
try {
if (XAO::XaoExporter::readFromFile(theFileName, theXao)) {