Commit 35a38360 authored by David Thompson's avatar David Thompson
Browse files

Expose the Operator class in Python and add tests.

These tests use the CGM operators from Python.
parent c69fb5c3
......@@ -14,6 +14,7 @@
#include "smtk/bridge/cgm/Engines.h"
#include "smtk/bridge/cgm/TDUUID.h"
#include "smtk/model/CellEntity.h"
#include "smtk/model/Manager.h"
#include "smtk/model/ModelEntity.h"
......@@ -68,7 +69,7 @@ smtk::model::OperatorResult BooleanUnionOperator::operateInternal()
if (cgmBody)
cgmBodiesIn.append(cgmBody);
if (!keepInputs)
this->manager()->erase(it->entity());
this->manager()->eraseModel(*it);
}
if (cgmBodiesIn.size() < 2)
......
......@@ -11,10 +11,15 @@
#include "smtk/bridge/cgm/CAUUID.h"
#include "smtk/Options.h"
#ifndef _MSC_VER
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored"-Wunused-parameter"
#endif
#ifdef CGM_HAVE_VERSION_H
# include "cgm_version.h"
#endif
#include "DLIList.hpp"
#include "FacetModifyEngine.hpp"
#include "GeometryHealerTool.hpp"
......@@ -103,10 +108,12 @@ bool Engines::isInitialized(const std::string& engine, const std::vector<std::st
bool Engines::setDefault(const std::string& engine)
{
// If we've never called init, do some extra stuff:
#if defined(CGM_VERSION_MAJOR) && CGM_VERSION_MAJOR >= 14
if (!Engines::areInitialized())
{
return Engines::isInitialized(engine);
}
#endif
// Otherwise, see if we can create the appropriate engines
// and set them in the default query/modify tool.
......
add_subdirectory(cxx)
if(SMTK_BUILD_PYTHON_WRAPPINGS AND Shiboken_FOUND)
add_subdirectory(python)
endif()
set(smtkCGMBridgePythonTests
cgmSolidModeling
)
# Additional tests that require SMTK_DATA_DIR
set(smtkCGMBridgePythonDataTests
cgmLoadFile
)
find_package( PythonInterp 2.7 )
if( PYTHONINTERP_FOUND )
set(LIB_ENV_VAR "")
if(APPLE AND UNIX)
set(LIB_ENV_VAR "DYLD_LIBRARY_PATH=${SHIBOKEN_LIBRARY_PATH}")
elseif(UNIX)
set(LIB_ENV_VAR "LD_LIBRARY_PATH=${SHIBOKEN_LIBRARY_PATH}")
endif()
set(SHIBOKEN_SMTK_PYTHON "")
if(UNIX)
set(SHIBOKEN_SMTK_PYTHON "${CMAKE_BINARY_DIR}:${SHIBOKEN_LIBRARY_PATH}")
else() #windows
set(SHIBOKEN_SMTK_PYTHON "${CMAKE_BINARY_DIR};${SHIBOKEN_LIBRARY_PATH}")
endif()
foreach (test ${smtkCGMBridgePythonTests})
add_test(${test}Py ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/${test}.py)
set_tests_properties(${test}Py
PROPERTIES
ENVIRONMENT "PYTHONPATH=${SHIBOKEN_SMTK_PYTHON};${LIB_ENV_VAR}"
)
endforeach()
if (SMTK_DATA_DIR AND EXISTS ${SMTK_DATA_DIR}/ReadMe.mkd)
foreach (test ${smtkCGMBridgePythonDataTests})
add_test(${test}Py
${PYTHON_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/${test}.py
${SMTK_DATA_DIR})
set_tests_properties(${test}Py
PROPERTIES
ENVIRONMENT "PYTHONPATH=${SHIBOKEN_SMTK_PYTHON};${LIB_ENV_VAR}"
)
endforeach()
endif()
else()
message("could not find python interp")
endif()
import sys
import os
sys.path.append('/Users/dcthomp/Build/SMTK/public')
sys.path.append('/Users/dcthomp/Build/SMTK/public/lib')
print sys.path
import smtk
try:
import cgmsmtk
except:
print "Expected"
ddir = sys.argv[-1]
mgr = smtk.model.Manager.create()
brg = smtk.model.Manager.createBridge('cgm')
mgr.registerBridgeSession(brg)
readop = brg.op('read', mgr)
readop.findFile('filename').setValue(os.path.join(ddir,'cgm','62_shaver1.brep'))
# Note that we could set the file type here:
# readop.findString('filetype').setValue('OCC')
# but there is no need to in this case as it will be
# correctly inferred from the filename.
res = readop.operate()
import smtk
try:
import cgmsmtk
except:
print "Expected"
mgr = smtk.model.Manager.create()
brg = smtk.model.Manager.createBridge('cgm')
brg.name()
brg.sessionId()
mgr.registerBridgeSession(brg)
opnames = brg.operatorNames()
cs1 = brg.op('create sphere', mgr)
cs1.findDouble('radius').setValue(1.)
#cs1.findDouble('inner radius').setValue(0.1) # Crashes
#cs1.findDouble('inner radius').setValue(-0.1) # Complains bitterly
cs1.findDouble('inner radius').setValue(0.2) # Actually works
# CGM's OCC backend apparently does not pay attention to
# the sphere center parameters:
cs1.findDouble('center').setValue(0, 0.2)
cs1.findDouble('center').setValue(1, 0.2)
cs1.findDouble('center').setValue(2, 0.2)
res = cs1.operate()
sph = res.findModelEntity('bodies').value(0)
cs2 = brg.op('create sphere', mgr)
cs2.findDouble('radius').setValue(0.5)
res2 = cs2.operate()
sph2 = res2.findModelEntity('bodies').value(0)
u1 = brg.op('union', mgr)
u1.associateEntity(sph)
u1.associateEntity(sph2)
res = u1.operate()
# You will see:
# Updated volume(s): 2
# Destroyed volume(s): 1
su = res.findModelEntity('bodies').value(0)
# Note that su has same UUID as sph2
#json = smtk.io.ExportJSON.fromModel(mgr)
#sphFile = open('/tmp/s3.json', 'w')
#print >> sphFile, json
#sphFile.close()
......@@ -23,10 +23,13 @@
<suppress-warning text="skipping function 'smtk::bridge::cgm::Bridge::addFaceUseToManager', unmatched parameter type 'CoFace*'"/>
<suppress-warning text="skipping function 'smtk::bridge::cgm::Bridge::addVolumeUseToManager', unmatched parameter type 'CoVolume*'"/>
<suppress-warning text="skipping function 'smtk::bridge::cgm::Bridge::addShellToManager', unmatched parameter type 'Shell*'"/>
<suppress-warning text="skipping function 'smtk::bridge::cgm::Bridge::addNamesIfAny', unmatched parameter type 'RefEntity*'"/>
<suppress-warning text="skipping function 'smtk::bridge::cgm::Bridge::addRelations', unmatched parameter type 'DLIList&lt;RefEntity*&gt;&amp;'"/>
<suppress-warning text="skipping function 'smtk::bridge::cgm::Bridge::addTessellation', unmatched parameter type 'RefEdge*'"/>
<suppress-warning text="skipping function 'smtk::bridge::cgm::Bridge::addTessellation', unmatched parameter type 'RefVertex*'"/>
<suppress-warning text="skipping function 'smtk::bridge::cgm::Bridge::addTessellation', unmatched parameter type 'RefFace*'"/>
<suppress-warning text="skipping function 'smtk::bridge::cgm::Bridge::registerOperator', unmatched parameter type 'smtk::model::OperatorConstructor'"/>
<suppress-warning text="skipping function 'smtk::bridge::cgm::Bridge::findOperatorConstructor', unmatched return type 'smtk::model::OperatorConstructor'"/>
<suppress-warning text="skipping field 'Bridge::s_operators' with unmatched type 'std::map&lt;std::string,smtk::model::StaticOperatorInfo&gt;'"/>
......
......@@ -321,6 +321,7 @@ std::string Bridge::findOperatorXMLInternal(
return it->second.first;
}
#ifndef SHIBOKEN_SKIP
/**\brief A convenience method used by subclass findOperatorConstructor methods.
*/
OperatorConstructor Bridge::findOperatorConstructorInternal(
......@@ -339,6 +340,7 @@ OperatorConstructor Bridge::findOperatorConstructorInternal(
}
return it->second.second;
}
#endif // SHIBOKEN_SKIP
/**\brief Subclasses may override this method to export additional state.
*
......
......@@ -67,6 +67,7 @@ enum BridgedInformation
/// Bit-vector combinations of BridgedInformation values for requesting information to transcribe.
typedef unsigned long BridgedInfoBits;
#ifndef SHIBOKEN_SKIP
/**\brief Declare that a class implements a bridge to a solid modeling kernel.
*
* Invoke this macro inside every class definition inheriting smtk::model::Bridge.
......@@ -190,6 +191,20 @@ public: \
virtual smtk::model::OperatorConstructor findOperatorConstructor( \
const std::string& opName) const;
#else // SHIBOKEN_SKIP
#define smtkImplementsModelingKernel(Comp, Tags, Setup, Cls) \
std::string Cls ::bridgeName(#Comp); \
std::string Cls ::className() const; \
std::string Cls ::findOperatorXML(const std::string& opName) const;
#define smtkDeclareModelingKernel() \
static std::string bridgeName; \
virtual std::string name(); \
virtual std::string className() const;
#endif // SHIBOKEN_SKIP
/**\brief A base class for bridging modelers into SMTK.
*
* SMTK can act as a bridge between other (foreign) solid modelers
......@@ -246,8 +261,10 @@ public:
smtk::attribute::System* operatorSystem();
const smtk::attribute::System* operatorSystem() const;
#ifndef SHIBOKEN_SKIP
virtual OperatorConstructor findOperatorConstructor(const std::string&) const
{ return OperatorConstructor(); }
#endif // SHIBOKEN_SKIP
virtual std::string findOperatorXML(const std::string&) const
{ return std::string(); }
......@@ -265,9 +282,11 @@ protected:
void setSessionId(const smtk::common::UUID& sessId);
#ifndef SHIBOKEN_SKIP
void initializeOperatorSystem(const OperatorConstructors* opList, bool inheritSubclass = false);
virtual OperatorConstructor findOperatorConstructorInternal(const std::string&, const OperatorConstructors* opList) const;
virtual std::string findOperatorXMLInternal(const std::string&, const OperatorConstructors* opList) const;
#endif // SHIBOKEN_SKIP
virtual BridgeIOPtr createIODelegate(const std::string& format);
......
......@@ -27,10 +27,12 @@
namespace smtk {
namespace model {
#ifndef SHIBOKEN_SKIP
//typedef smtk::function<smtk::model::OperatorPtr()> OperatorConstructor;
typedef smtk::model::OperatorPtr (*OperatorConstructor)();
typedef std::pair<std::string,OperatorConstructor> StaticOperatorInfo;
typedef std::map<std::string,StaticOperatorInfo> OperatorConstructors;
#endif
/**\brief An enumeration of operation outcomes (or lacks thereof).
*
......@@ -141,6 +143,7 @@ public:
virtual bool ableToOperate() { return false; }
virtual OperatorResult operate();
#ifndef SHIBOKEN_SKIP
void observe(OperatorEventType event, WillOperateCallback functionHandle, void* callData);
void observe(OperatorEventType event, DidOperateCallback functionHandle, void* callData);
......@@ -149,6 +152,7 @@ public:
int trigger(OperatorEventType event);
int trigger(OperatorEventType event, const OperatorResult& result);
#endif // SHIBOKEN_SKIP
ManagerPtr manager() const;
Ptr setManager(ManagerPtr s);
......@@ -178,7 +182,9 @@ public:
OperatorResult createResult(OperatorOutcome outcome = UNABLE_TO_OPERATE);
void eraseResult(OperatorResult res);
#ifndef SHIBOKEN_SKIP
bool operator < (const Operator& other) const;
#endif // SHIBOKEN_SKIP
protected:
friend class DefaultBridge;
......@@ -188,11 +194,13 @@ protected:
virtual OperatorResult operateInternal() = 0;
#ifndef SHIBOKEN_SKIP
ManagerPtr m_manager; // Model manager, not the attribute manager for the operator.
Bridge* m_bridge;
OperatorSpecification m_specification;
std::set<WillOperateObserver> m_willOperateTriggers;
std::set<DidOperateObserver> m_didOperateTriggers;
#endif // SHIBOKEN_SKIP
};
SMTKCORE_EXPORT std::string outcomeAsString(int oc);
......
......@@ -212,6 +212,7 @@
<suppress-warning text="template baseclass 'smtk::enable_shared_from_this&lt;__VA_ARGS__&gt;' of 'BRepModel' is not known"/>
<suppress-warning text="template baseclass 'smtk::enable_shared_from_this&lt;__VA_ARGS__&gt;' of 'Bridge' is not known"/>
<suppress-warning text="template baseclass 'smtk::enable_shared_from_this&lt;__VA_ARGS__&gt;' of 'DescriptivePhrase' is not known"/>
<suppress-warning text="template baseclass 'smtk::enable_shared_from_this&lt;__VA_ARGS__&gt;' of 'Operator' is not known"/>
<suppress-warning text="skipping function 'smtk::model::BRepModel::create', unmatched return type 'smtk::shared_ptr&lt;smtk::model::BRepModel::SelfType&gt;'"/>
<suppress-warning text="skipping function 'smtk::model::Manager::create', unmatched return type 'smtk::shared_ptr&lt;smtk::model::Manager::SelfType&gt;'"/>
<suppress-warning text="skipping function 'smtk::model::Manager::shared_from_this', unmatched return type 'smtk::shared_ptr&lt;smtk::model::Manager::SelfType&gt;'"/>
......@@ -275,21 +276,20 @@
<!-- Ignore until we have time to support Operators -->
<suppress-warning text="skipping field 'BRepModel::m_modelBridges' with unmatched type 'std::map&lt;smtk::io::UUID,smtk::shared_ptr&lt;Bridge&gt;&gt;'"/>
<suppress-warning text="skipping field 'BRepModel::m_defaultBridge' with unmatched type 'smtk::shared_ptr&lt;Bridge&gt;'"/>
<suppress-warning text="skipping field 'Bridge::m_operators' with unmatched type 'std::set&lt;smtk::model::OperatorPtr&gt;'"/>
<suppress-warning text="skipping function 'smtk::model::Manager::shared_from_this', unmatched return type 'smtk::shared_ptr&lt;const smtk::model::Manager::SelfType&gt;'"/>
<suppress-warning text="skipping function 'smtk::model::Bridge::addOperator', unmatched parameter type 'smtk::model::OperatorPtr'"/>
<suppress-warning text="skipping function 'smtk::model::Bridge::op', unmatched return type 'smtk::model::OperatorPtr'"/>
<suppress-warning text="skipping function 'smtk::model::Bridge::findOperatorXMLInternal', unmatched parameter type 'smtk::model::OperatorConstructors const*'"/>
<suppress-warning text="skipping function 'smtk::model::ModelEntity::operators', unmatched return type 'smtk::model::Operators'"/>
<suppress-warning text="skipping function 'smtk::model::EntityListPhrase::shared_from_this', unmatched return type 'smtk::shared_ptr&lt;const smtk::model::EntityListPhrase::SelfType&gt;'"/>
<suppress-warning text="skipping function 'smtk::model::EntityPhrase::shared_from_this', unmatched return type 'smtk::shared_ptr&lt;const smtk::model::EntityPhrase::SelfType&gt;'"/>
<suppress-warning text="skipping function 'smtk::model::SimpleModelSubphrases::shared_from_this', unmatched return type 'smtk::shared_ptr&lt;const smtk::model::SimpleModelSubphrases::SelfType&gt;'"/>
<suppress-warning text="skipping function 'smtk::model::ModelEntity::op', unmatched return type 'smtk::model::OperatorPtr'"/>
<suppress-warning text="skipping function 'smtk::model::Operator::setManager', unmatched return type 'smtk::model::Operator::Ptr'"/>
<suppress-warning text="skipping function 'smtk::model::Operator::setBridge', unmatched return type 'smtk::model::Operator::Ptr'"/>
<suppress-warning text="skipping function 'smtk::model::Operator::associatedEntitiesAs', unmatched return type 'T'"/>
<suppress-warning text="skipping field 'BRepModel::s_bridges' with unmatched type 'std::map&lt;std::string,smtk::model::StaticBridgeInfo&gt;'"/>
<suppress-warning text="skipping function 'smtk::model::BRepModel::registerBridge', unmatched parameter type 'smtk::model::BridgeConstructor'"/>
<suppress-warning text="skipping function 'smtk::model::BRepModel::bridgeConstructor', unmatched return type 'smtk::model::BridgeConstructor'"/>
<suppress-warning text="skipping function 'smtk::io::ExportJSON::forOperator', unmatched parameter type 'smtk::model::OperatorPtr'"/>
<suppress-warning text="skipping field 'BRepModel::m_sessions' with unmatched type 'std::map&lt;smtk::common::UUID,smtk::shared_ptr&lt;Bridge&gt;&gt;'"/>
......@@ -634,6 +634,7 @@
<value-type template="smtk::shared_ptr" args="smtk::model::EntityListPhrase"/>
<value-type template="smtk::shared_ptr" args="smtk::model::BRepModel"/>
<value-type template="smtk::shared_ptr" args="smtk::model::SimpleModelSubphrases"/>
<value-type template="smtk::shared_ptr" args="smtk::model::Operator"/>
<value-type template="smtk::shared_ptr" args="smtk::model::Manager">
<modify-function signature="arrangeEntity(smtk::common::UUID,smtk::model::ArrangementKind,smtk::model::Arrangement,int)">
<inject-code class="target" position="beginning">
......@@ -862,6 +863,10 @@
<include file-name="smtk/model/Operator.h" location="local"/>
</enum-type>
<object-type name="Operator">
<include file-name="smtk/model/Operator.h" location="local"/>
</object-type>
<object-type name="AttributeAssignments">
<include file-name="smtk/model/AttributeAssignments.h" location="local"/>
</object-type>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment