diff --git a/smtk/bridge/mesh/CMakeLists.txt b/smtk/bridge/mesh/CMakeLists.txt index 82e9005efa2a68c40446e3e2821abda14b13cb68..7913cac4d5b5851453aa6082dc0b1389ce184041 100644 --- a/smtk/bridge/mesh/CMakeLists.txt +++ b/smtk/bridge/mesh/CMakeLists.txt @@ -1,16 +1,18 @@ set(meshSrcs - Session.cxx + ImportOperator.cxx Operator.cxx ReadOperator.cxx + Session.cxx Topology.cxx WriteOperator.cxx ) set(meshHeaders - Session.h + ImportOperator.h Operator.h PointerDefs.h ReadOperator.h + Session.h Topology.h WriteOperator.h ) @@ -38,6 +40,7 @@ smtk_install_library(smtkMeshSession) # We do not need the path to the generated header (appended # to meshOperatorXML) since the operators themselves include # the header in their implementations. +smtk_operator_xml("${CMAKE_CURRENT_SOURCE_DIR}/ImportOperator.sbt" meshOperatorXML) smtk_operator_xml("${CMAKE_CURRENT_SOURCE_DIR}/ReadOperator.sbt" meshOperatorXML) smtk_operator_xml("${CMAKE_CURRENT_SOURCE_DIR}/WriteOperator.sbt" meshOperatorXML) smtk_session_json("${CMAKE_CURRENT_SOURCE_DIR}/Session.json" meshSessionJSON) diff --git a/smtk/bridge/mesh/ImportOperator.cxx b/smtk/bridge/mesh/ImportOperator.cxx new file mode 100644 index 0000000000000000000000000000000000000000..858942422624dfc6f922f83f87da20053fdba182 --- /dev/null +++ b/smtk/bridge/mesh/ImportOperator.cxx @@ -0,0 +1,109 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//========================================================================= +#include "smtk/bridge/mesh/ImportOperator.h" + +#include "smtk/bridge/mesh/Session.h" + +#include "smtk/attribute/Attribute.h" +#include "smtk/attribute/FileItem.h" +#include "smtk/attribute/IntItem.h" +#include "smtk/attribute/ModelEntityItem.h" +#include "smtk/attribute/StringItem.h" + +#include "smtk/io/ImportMesh.h" + +#include "smtk/model/Group.h" +#include "smtk/model/Manager.h" +#include "smtk/model/Model.h" + +#include "smtk/common/CompilerInformation.h" + +using namespace smtk::model; +using namespace smtk::common; + +namespace smtk { +namespace bridge { +namespace mesh { + +smtk::model::OperatorResult ImportOperator::operateInternal() +{ + // Get the read file name + smtk::attribute::FileItem::Ptr filePathItem = + this->specification()->findFile("filename"); + std::string filePath = filePathItem->value(); + + smtk::attribute::StringItem::Ptr labelItem = + this->specification()->findString("label"); + std::string label = labelItem->value(); + + // Get the collection from the file + smtk::mesh::CollectionPtr collection = + smtk::io::importMesh(filePath, this->activeSession()->meshManager(), label); + + if (!collection->isValid()) + { + // The file was not correctly read. + return this->createResult(smtk::model::OPERATION_FAILED); + } + + // Assign its model manager to the one associated with this session + collection->setModelManager(this->activeSession()->manager()); + + // Construct the topology + this->activeSession()->addTopology(std::move(Topology(collection))); + + // Our collections will already have a UUID, so here we create a model given + // the model manager and uuid + smtk::model::Model model = + smtk::model::EntityRef(this->activeSession()->manager(), + collection->entity()); + + collection->associateToModel(model.entity()); + + // Set the model's session to point to the current session + model.setSession(smtk::model::SessionRef(this->activeSession()->manager(), + this->activeSession()->sessionId())); + + // If we don't call "transcribe" ourselves, it never gets called. + this->activeSession()->transcribe( + model, smtk::model::SESSION_EVERYTHING, false); + + smtk::model::OperatorResult result = + this->createResult(smtk::model::OPERATION_SUCCEEDED); + + smtk::attribute::ModelEntityItem::Ptr resultModels = + result->findModelEntity("model"); + resultModels->setValue(model); + + smtk::attribute::ModelEntityItem::Ptr created = + result->findModelEntity("created"); + created->setNumberOfValues(1); + created->setValue(model); + created->setIsEnabled(true); + + result->findModelEntity("mesh_created")->setValue(model); + + return result; +} + +} // namespace mesh +} //namespace bridge +} // namespace smtk + +#include "smtk/bridge/mesh/ImportOperator_xml.h" +#include "smtk/bridge/mesh/Exports.h" + +smtkImplementsModelOperator( + SMTKMESHSESSION_EXPORT, + smtk::bridge::mesh::ImportOperator, + mesh_import, + "import", + ImportOperator_xml, + smtk::bridge::mesh::Session); diff --git a/smtk/bridge/mesh/ImportOperator.h b/smtk/bridge/mesh/ImportOperator.h new file mode 100644 index 0000000000000000000000000000000000000000..ade0867dcf725cd9febcbb78822c399e6385d728 --- /dev/null +++ b/smtk/bridge/mesh/ImportOperator.h @@ -0,0 +1,35 @@ +//========================================================================= +// Copyright (c) Kitware, Inc. +// All rights reserved. +// See LICENSE.txt for details. +// +// This software is distributed WITHOUT ANY WARRANTY; without even +// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the above copyright notice for more information. +//========================================================================= +#ifndef __smtk_session_mesh_ImportOperator_h +#define __smtk_session_mesh_ImportOperator_h + +#include "smtk/bridge/mesh/Operator.h" + +namespace smtk { + namespace bridge { + namespace mesh { + +class SMTKMESHSESSION_EXPORT ImportOperator : public Operator +{ +public: + smtkTypeMacro(ImportOperator); + smtkCreateMacro(ImportOperator); + smtkSharedFromThisMacro(Operator); + smtkDeclareModelOperator(); + +protected: + virtual smtk::model::OperatorResult operateInternal(); +}; + + } // namespace mesh + } // namespace bridge +} // namespace smtk + +#endif // __smtk_session_mesh_ImportOperator_h diff --git a/smtk/bridge/mesh/ImportOperator.sbt b/smtk/bridge/mesh/ImportOperator.sbt new file mode 100644 index 0000000000000000000000000000000000000000..b3658afc1a90a816949cdc020738b0182c16bf12 --- /dev/null +++ b/smtk/bridge/mesh/ImportOperator.sbt @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8" ?> +<!-- Description of the Mesh "Import" Operator --> +<SMTK_AttributeSystem Version="2"> + <Definitions> + <!-- Operator --> + <AttDef Type="import" BaseType="operator"> + <ItemDefinitions> + <File Name="filename" NumberOfRequiredValues="1" + ShouldExist="true" + FileFilters="Moab files (*.h5m);;Exodus II Datasets (*.e *.exo *.ex2);;VTK files (*.vtu *.vtp *.vtk);;All files (*.*)"> + </File> + <String Name="label" NumberOfRequiredValues="1"> + <DefaultValue></DefaultValue> + </String> + <String Name="filetype" NumberOfRequiredValues="1" Optional="true" IsEnabledByDefault="false"/> + </ItemDefinitions> + </AttDef> + <!-- Result --> + <AttDef Type="result(import)" BaseType="result"> + <ItemDefinitions> + <!-- The model imported from the file. --> + <ModelEntity Name="model" NumberOfRequiredValues="1" Extensible="1" MembershipMask="4096"/> + <ModelEntity Name="mesh_created" NumberOfRequiredValues="1"/> + </ItemDefinitions> + </AttDef> + </Definitions> +</SMTK_AttributeSystem> diff --git a/smtk/extension/vtk/io/MeshIOVTK.cxx b/smtk/extension/vtk/io/MeshIOVTK.cxx index 99989af2a3bc9e77dce72e9d8d68bf79db5b4a8c..68a4b579ddd96ce1f177a60f4e0156d1c332c41b 100644 --- a/smtk/extension/vtk/io/MeshIOVTK.cxx +++ b/smtk/extension/vtk/io/MeshIOVTK.cxx @@ -40,17 +40,19 @@ MeshIOVTK::MeshIOVTK() : MeshIO() smtk::mesh::CollectionPtr MeshIOVTK::importMesh( const std::string& filePath, - smtk::mesh::ManagerPtr& manager ) const + smtk::mesh::ManagerPtr& manager, + const std::string& domainPropertyName ) const { smtk::extension::vtk::io::VTKDataConverter convert; - return convert( filePath, manager, std::string() ); + return convert( filePath, manager, domainPropertyName ); } bool MeshIOVTK::importMesh( const std::string& filePath, - smtk::mesh::CollectionPtr collection ) const + smtk::mesh::CollectionPtr collection, + const std::string& domainPropertyName ) const { smtk::extension::vtk::io::VTKDataConverter convert; - return convert( filePath, collection, std::string() ); + return convert( filePath, collection, domainPropertyName ); } } diff --git a/smtk/extension/vtk/io/MeshIOVTK.h b/smtk/extension/vtk/io/MeshIOVTK.h index f2b4e188bbfeb00a13a8d7c9c70e0d266e171c3a..3dc88843f2d6a8002d27d08a7d68a9288df5c918 100644 --- a/smtk/extension/vtk/io/MeshIOVTK.h +++ b/smtk/extension/vtk/io/MeshIOVTK.h @@ -39,11 +39,13 @@ public: //file can't be loaded smtk::mesh::CollectionPtr importMesh( const std::string& filePath, - smtk::mesh::ManagerPtr& manager ) const override; + smtk::mesh::ManagerPtr& manager, + const std::string& domainPropertyName ) const override; //Merge a vtk data file into an existing valid collection. bool importMesh( const std::string& filePath, - smtk::mesh::CollectionPtr collection ) const override; + smtk::mesh::CollectionPtr collection, + const std::string& domainPropertyName ) const override; }; } diff --git a/smtk/io/ImportMesh.cxx b/smtk/io/ImportMesh.cxx index 4e047f3355a37224f966f6aec0334824bc45e20e..0f5caadddeed4f24601f33b69720d6d031270753 100644 --- a/smtk/io/ImportMesh.cxx +++ b/smtk/io/ImportMesh.cxx @@ -46,8 +46,10 @@ std::vector<smtk::io::mesh::MeshIOPtr>& ImportMesh::SupportedIOTypes() return supportedIOTypes; } -smtk::mesh::CollectionPtr ImportMesh::operator() (const std::string& filePath, - smtk::mesh::ManagerPtr manager) const +smtk::mesh::CollectionPtr ImportMesh::operator() ( + const std::string& filePath, + smtk::mesh::ManagerPtr manager, + std::string domainPropertyName) const { // Grab the file extension std::string ext = boost::filesystem::extension(filePath); @@ -65,7 +67,8 @@ smtk::mesh::CollectionPtr ImportMesh::operator() (const std::string& filePath, format.Extensions.end() ) { // import the collection - collection = importer->importMesh(filePath, manager); + collection = importer->importMesh(filePath, manager, + domainPropertyName); break; } } @@ -75,7 +78,8 @@ smtk::mesh::CollectionPtr ImportMesh::operator() (const std::string& filePath, } bool ImportMesh::operator() (const std::string& filePath, - smtk::mesh::CollectionPtr collection) const + smtk::mesh::CollectionPtr collection, + std::string domainPropertyName) const { // Grab the file extension std::string ext = boost::filesystem::extension(filePath); @@ -91,7 +95,7 @@ bool ImportMesh::operator() (const std::string& filePath, format.Extensions.end() ) { // import the collection - return importer->importMesh(filePath, collection); + return importer->importMesh(filePath, collection, domainPropertyName); } } } @@ -102,14 +106,30 @@ smtk::mesh::CollectionPtr importMesh(const std::string& filePath, smtk::mesh::ManagerPtr manager) { ImportMesh importM; - return importM( filePath, manager ); + return importM( filePath, manager, std::string() ); +} + +smtk::mesh::CollectionPtr importMesh(const std::string& filePath, + smtk::mesh::ManagerPtr manager, + const std::string& domainPropertyName) +{ + ImportMesh importM; + return importM( filePath, manager, domainPropertyName ); } bool importMesh(const std::string& filePath, smtk::mesh::CollectionPtr collection) { ImportMesh importM; - return importM( filePath, collection ); + return importM( filePath, collection, std::string() ); +} + +bool importMesh(const std::string& filePath, + smtk::mesh::CollectionPtr collection, + const std::string& domainPropertyName) +{ + ImportMesh importM; + return importM( filePath, collection, domainPropertyName ); } } diff --git a/smtk/io/ImportMesh.h b/smtk/io/ImportMesh.h index 01b0ed4e49fd58cb81da4f6bc7771c2fd6de8138..6182583d2d83b0d94d1d9f0a1404ad7bba380cf0 100644 --- a/smtk/io/ImportMesh.h +++ b/smtk/io/ImportMesh.h @@ -37,22 +37,33 @@ public: ImportMesh(const ImportMesh&) = delete; static std::vector<smtk::io::mesh::MeshIOPtr>& SupportedIOTypes(); -#endif //Load the domain sets from a moab data file as a new collection into the //given manager. - smtk::mesh::CollectionPtr operator() (const std::string& filePath, - smtk::mesh::ManagerPtr manager) const; + smtk::mesh::CollectionPtr operator() + (const std::string& filePath, + smtk::mesh::ManagerPtr manager, + std::string domainPropertyName = std::string()) const; bool operator() (const std::string& filePath, - smtk::mesh::CollectionPtr collection) const; + smtk::mesh::CollectionPtr collection, + std::string domainPropertyName = std::string()) const; +#endif }; SMTKCORE_EXPORT smtk::mesh::CollectionPtr importMesh(const std::string& filePath, smtk::mesh::ManagerPtr manager); +SMTKCORE_EXPORT smtk::mesh::CollectionPtr +importMesh(const std::string& filePath, + smtk::mesh::ManagerPtr manager, + const std::string& domainPropertyName); SMTKCORE_EXPORT bool importMesh(const std::string& filePath, smtk::mesh::CollectionPtr collection); +SMTKCORE_EXPORT bool +importMesh(const std::string& filePath, + smtk::mesh::CollectionPtr collection, + const std::string& domainPropertyName); } } diff --git a/smtk/io/mesh/MeshIO.h b/smtk/io/mesh/MeshIO.h index 6dc11e993f43c153b4881d488dc77bffebf690a5..2490a85b803bd960d1bd5862c6299b8fefc03106 100644 --- a/smtk/io/mesh/MeshIO.h +++ b/smtk/io/mesh/MeshIO.h @@ -48,11 +48,13 @@ public: virtual smtk::mesh::CollectionPtr importMesh( const std::string&, - smtk::mesh::ManagerPtr& ) const + smtk::mesh::ManagerPtr&, + const std::string& ) const { return smtk::mesh::CollectionPtr(); } virtual bool importMesh( const std::string&, - smtk::mesh::CollectionPtr ) const { return false; } + smtk::mesh::CollectionPtr, + const std::string& ) const { return false; } virtual bool exportMesh( const std::string&, smtk::mesh::CollectionPtr ) const { return false; } diff --git a/smtk/io/mesh/MeshIOMoab.cxx b/smtk/io/mesh/MeshIOMoab.cxx index 7fc3f7c8048c7ac2603571f7a91c598237c07c08..7eece39d151c2a10de802ece4492e800a3be4af1 100644 --- a/smtk/io/mesh/MeshIOMoab.cxx +++ b/smtk/io/mesh/MeshIOMoab.cxx @@ -59,13 +59,15 @@ MeshIOMoab::MeshIOMoab() : MeshIO() smtk::mesh::CollectionPtr MeshIOMoab::importMesh( const std::string& filePath, - smtk::mesh::ManagerPtr& manager ) const + smtk::mesh::ManagerPtr& manager, + const std::string& ) const { return this->read( filePath, manager, Subset::EntireCollection ); } bool MeshIOMoab::importMesh( const std::string& filePath, - smtk::mesh::CollectionPtr collection ) const + smtk::mesh::CollectionPtr collection, + const std::string& ) const { return this->read( filePath, collection, Subset::EntireCollection ); } diff --git a/smtk/io/mesh/MeshIOMoab.h b/smtk/io/mesh/MeshIOMoab.h index 32a7b3df0e6310d3950bbf1f8ca62c8d41a9f435..cf999d3d8b5d6f69993fa56901c15d94295c9dcb 100644 --- a/smtk/io/mesh/MeshIOMoab.h +++ b/smtk/io/mesh/MeshIOMoab.h @@ -32,14 +32,19 @@ public: //Load an entire moab data file as a new collection into the given manager //Returns an invalid collection that is NOT part of the manager if the - //file can't be loaded + //file can't be loaded. The third parameter is a label with which the domain + //can be parsed, but it is not currently implemented for the moab interface smtk::mesh::CollectionPtr importMesh( const std::string& filePath, - smtk::mesh::ManagerPtr& manager ) const override; + smtk::mesh::ManagerPtr& manager, + const std::string& ) const override; - //Merge a moab data file into an existing valid collection. + //Merge a moab data file into an existing valid collection. The third + //parameter is a label with which the domain can be parsed, but it is not + //currently implemented for the moab interface bool importMesh( const std::string& filePath, - smtk::mesh::CollectionPtr collection ) const override; + smtk::mesh::CollectionPtr collection, + const std::string& ) const override; //Exports the collection to file. Overwrites any existing content in the file bool exportMesh( const std::string& filePath,