60 #include <osg/Material>
61 #include <osg/ShapeDrawable>
62 #include <osg/StateAttribute>
64 #include "WMTemplate.h"
65 #include "core/common/WColor.h"
66 #include "core/common/WItemSelection.h"
67 #include "core/common/WItemSelectionItem.h"
68 #include "core/common/WItemSelector.h"
69 #include "core/common/WPathHelper.h"
70 #include "core/common/WPropertyHelper.h"
71 #include "core/common/exceptions/WFileNotFound.h"
72 #include "core/graphicsEngine/WGERequirement.h"
73 #include "core/graphicsEngine/WGEUtils.h"
74 #include "core/kernel/WKernel.h"
75 #include "icons/bier.xpm"
76 #include "icons/steak.xpm"
77 #include "icons/wurst.xpm"
122 return std::shared_ptr< WModule >(
new WMTemplate() );
143 return "This module is intended to be a module template and an example for writing modules.";
195 "A property which gets modified if \"Number of shape rows\" gets modified.", 10 );
199 m_aColor =
m_properties->addProperty(
"A color",
"Description.", WColor( 1.0, 0.0, 0.0, 1.0 ) );
243 "Description for the first option"
249 "Description for the second option"
266 m_group1a =
m_group1->addPropertyGroup(
"Group 1a",
"A group nested into \"Group 1\"." );
267 m_group2 =
m_properties->addPropertyGroup(
"Second Group",
"Another nice group for grouping stuff." );
271 WPropGroup group =
m_properties->addPropertyGroup(
"Group Nesting - Level 0",
"Demo for intensive group nesting." );
272 for(
int d = 1; d <= 20; ++d )
275 group = group->addPropertyGroup(
"Group Nesting - Level " + depth,
"A nested group." );
290 m_aHiddenInt =
m_group2->addProperty(
"Hide me please",
"A property used to demonstrate the hidden feature.", 1,
true );
291 m_aHiddenGroup =
m_group2->addPropertyGroup(
"Hide me please too",
"A property used to demonstrate the hidden feature.",
true );
349 std::string message = std::string(
"Hey you! Besides all these parameters, you also can print values, " ) +
350 std::string(
"<font color=\"#00f\" size=15>html</font> formatted strings, colors and " ) +
351 std::string(
"so on using <font color=\"#ff0000\">properties</font>! Isn't it <b>amazing</b>?" );
398 debugLog() <<
"Entering moduleMain()";
403 debugLog() <<
"Doing time consuming operations";
436 debugLog() <<
"Module is now ready.";
452 m_shader->setDefine(
"USE_MATERIAL_DIFFUSE" );
497 bool dataUpdated =
m_input->updated();
500 std::shared_ptr< WDataSetSingle > dataSet =
m_input->getData();
501 bool dataValid = ( dataSet != NULL );
512 if( dataUpdated && dataValid )
524 debugLog() <<
"Data changed. No valid data anymore. Cleaning up.";
540 debugLog() <<
"Doing an operation on the file \"" <<
m_aFile->get(
true ).string() <<
"\".";
549 debugLog() <<
"Doing an operation basing on m_aString ... ";
559 debugLog() <<
"Creating new OSG node";
571 debugLog() <<
"Number of Rows: " << rows;
573 debugLog() <<
"Current dataset: " << dataSet->getFilename() <<
" with name: " << dataSet->getName();
577 osg::ref_ptr< osg::Geode > newGeode =
new osg::Geode();
580 for( int32_t i = 0; i < rows; ++i )
582 newGeode->addDrawable(
583 new osg::ShapeDrawable(
new osg::Box( osg::Vec3( 25, 128, i * 15 ), radii ) ) );
584 newGeode->addDrawable(
585 new osg::ShapeDrawable(
new osg::Sphere( osg::Vec3( 75, 128, i * 15 ), radii ) ) );
586 newGeode->addDrawable(
587 new osg::ShapeDrawable(
new osg::Cone( osg::Vec3( 125, 128, i * 15 ), radii, radii ) ) );
588 newGeode->addDrawable(
589 new osg::ShapeDrawable(
new osg::Cylinder( osg::Vec3( 175, 128, i * 15 ), radii, radii ) ) );
590 newGeode->addDrawable(
591 new osg::ShapeDrawable(
new osg::Capsule( osg::Vec3( 225, 128, i * 15 ), radii, radii ) ) );
617 if( dataUpdated && dataValid )
619 debugLog() <<
"Data changed. Recalculating output.";
622 std::shared_ptr< WDataSetSingle > newData = dataSet;
629 std::shared_ptr< WProgress > progress1(
new WProgress(
"Doing work 1", steps ) );
631 for(
int i = 0; i < steps; ++i )
644 std::shared_ptr< WProgress > progress2(
new WProgress(
"Doing work 2" ) );
659 debugLog() <<
"User triggered an important and time consuming operation.";
679 std::shared_ptr< WProgress > progress1(
new WProgress(
"Doing something important", steps ) );
681 for(
int i = 0; i < steps; ++i )
705 infoLog() <<
"The user likes " << s.
at( 0 )->getName() <<
" the most.";
709 for(
size_t i = 0; i < s.
size(); ++i )
711 infoLog() <<
"The user likes " << s.
at( i )->getName();
722 ". Length: " << s.
at( 0 )->getAs<
MyItemType >()->getValue().length();
736 throw WFileNotFound(
"This is a demonstration of an exception being thrown from within a module." );
781 osg::ref_ptr< osg::Material > mat =
new osg::Material();
783 node->getOrCreateStateSet()->setAttribute( mat, osg::StateAttribute::ON );
785 traverse( node, nv );
791 if( m_module->m_aPosition->changed() || m_initialUpdate )
794 osg::ref_ptr< osg::MatrixTransform > transform =
static_cast< osg::MatrixTransform*
>( node );
797 osg::Matrixd translate = osg::Matrixd::translate( m_module->m_aPosition->get(
true ).as< osg::Vec3d >() );
800 transform->setMatrix( translate );
803 m_initialUpdate =
false;
805 traverse( node, nv );
817 return ( value.length() <= 10 ) && ( value.length() >= 5 );
824 return std::shared_ptr< WPropertyVariable< WPVBaseTypes::PV_STRING >::PropertyConstraint >(
new WMTemplate::StringLength( *
this ) );
virtual void wait() const
Wait for the condition.
void setResetable(bool resetable=true, bool autoReset=true)
Sets the resetable flag.
virtual void add(std::shared_ptr< WCondition > condition)
Adds another condition to the set of conditions to wait for.
Class to encapsulate boost::condition_variable_any.
Thrown whenever a file was not found.
This class adds some convenience methods to WGEGroupNode.
This requirement ensures an up and running WGE.
Class encapsulating the OSG Program class for a more convenient way of adding and modifying shader.
const T & getUpper() const
Return the upper value of the interval.
const T & getLower() const
Get the lower value of the interval.
A derivation of WItemSelection which can store a value of any type.
static SPtr create(T value, std::string name, std::string description="", const char **icon=NULL)
Create a instance of the item.
A class containing a list of named items.
std::shared_ptr< WItemSelection > SPtr
Convenience typedef for a std::shared_ptr< WItemSelection >
This class represents a subset of a WItemSelection.
virtual const std::shared_ptr< WItemSelectionItem > at(size_t index) const
Gets the selected item with the given index.
virtual size_t size() const
The number of selected items.
static WKernel * getRunningKernel()
Returns pointer to the currently running kernel.
std::shared_ptr< WGraphicsEngine > getGraphicsEngine() const
Returns pointer to currently running instance of graphics engine.
Node callback to change the color of the shapes inside the root node.
bool m_initialUpdate
Denotes whether the update callback is called the first time.
WMTemplate * m_module
Pointer used to access members of the module to modify the node.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
operator () - called during the update traversal.
This shows how to write custom constraints for your modules.
virtual bool accept(std::shared_ptr< WPropertyVariable< WPVBaseTypes::PV_STRING > > property, const WPVBaseTypes::PV_STRING &value)
You need to overwrite this method.
virtual std::shared_ptr< WPropertyVariable< WPVBaseTypes::PV_STRING >::PropertyConstraint > clone()
Method to clone the constraint and create a new one with the correct dynamic type.
Node callback to change the position of the shapes in the coordinate system of the scene.
virtual void operator()(osg::Node *node, osg::NodeVisitor *nv)
operator () - called during the update traversal.
WPropColor m_aColor
A color.
osg::ref_ptr< WGEManagedGroupNode > m_rootNode
The root node used for this modules graphics.
WPropPosition m_aPosition
A Property used to store some position.
WPropDouble m_aDouble
A double value.
WPropSelection m_aSingleSelection
A property allowing the user to select ONE item of some list.
WPropSelection m_aSelectionOutput
A Property used to show some selection to the user.
WPropTrigger m_aTriggerOutput
A Property used to show some trigger to the user.
WPropColor m_aColorOutput
A Property used to show some color to the user.
WPropFilename m_aFilenameOutput
A Property used to show some filename to the user.
osg::ref_ptr< osg::Geode > m_geode
The geometry rendered by this module.
WPropInterval m_anInterval
A property allowing you to define whole intervals.
virtual const std::string getDescription() const
Gives back a description of this module.
WPropTrigger m_exceptionTrigger
This causes an exception to be thrown on press to demonstrate how the GUI handles crashing modules.
virtual void requirements()
Initialize requirements for this module.
WPropInt m_aIntOutput
A property simply providing a int value to the outside world.
std::shared_ptr< WItemSelection > m_possibleSelectionsUsingTypes
A list of items that can be selected using m_aSingleSelectionUsingTypes property.
WPropInt m_anInteger
An integer value.
WPropInt m_anIntegerClone
An integer value.
WMTemplate()
Default constructor.
std::shared_ptr< WModuleOutputData< WDataSetSingle > > m_output
The output connector used to provide the calculated data to other modules.
virtual void properties()
Initialize the properties for this module.
WPropTrigger m_hideButton
A Property used to show the callback mechanism avoiding the thread wake up on change.
void hideButtonPressed()
The callback triggering the hide flag of m_aColor for demonstration.
virtual const char ** getXPMIcon() const
Get the icon for this module in XPM format.
WPropSelection m_aSingleSelectionUsingTypes
A property allowing the user to select ONE item.
std::shared_ptr< WItemSelection > m_possibleSelections
A list of items that can be selected using m_aSingleSelection or m_aMultiSelection.
WPropDouble m_aDoubleOutput
A property simply providing a double value to the outside world.
WPropBool m_group1Bool
A nice feature trigger inside m_group1.
WPropSelection m_aMultiSelection
A property allowing the user to select multiple elements of a list.
virtual void moduleMain()
Entry point after loading the module.
virtual void activate()
Callback for m_active.
virtual std::shared_ptr< WModule > factory() const
Due to the prototype design pattern used to build modules, this method returns a new instance of this...
WPropGroup m_group1a
To group properties, use WPropGroup.
WPropInt m_aHiddenInt
A int property used to show hide/un-hide feature.
virtual ~WMTemplate()
Destructor.
WPropString m_aStringOutput
A property simply providing some text to the outside world.
virtual const std::string getName() const
Gives back the name of this module.
WPropGroup m_group1
To group properties, use WPropGroup.
WGEShader::RefPtr m_shader
We want some nice shading effects, so we need a nice shader.
WPropGroup m_group2
To group properties, use WPropGroup.
std::shared_ptr< WModuleInputData< WDataSetSingle > > m_input
An input connector used to get datasets from other modules.
WPropInt m_aIntegerOutput
A property simply providing a integer value to the outside world.
WPropFilename m_aFile
A filename.
WPropString m_aString
A string.
WPropTrigger m_aTrigger
A trigger which can be used to trigger some kind of operation.
virtual void connectors()
Initialize the connectors this module is using.
WPropBool m_enableFeature
En/Disables an feature.
std::shared_ptr< WCondition > m_propCondition
A condition used to notify about changes in several properties.
WPropGroup m_aHiddenGroup
A group used to show that even hiding whole groups is possible.
Class offering an instantiate-able data connection between modules.
Class representing a single module of OpenWalnut.
boost::filesystem::path m_localPath
The path where the module binary resides in.
Requirements m_requirements
The list of requirements.
virtual void properties()
Initialize properties in this function.
wlog::WStreamedLogger debugLog() const
Logger instance for comfortable debug logging.
virtual WModuleMetaInformation::ConstSPtr getMetaInformation() const
The meta information of this module.
std::shared_ptr< WProperties > m_properties
The property object for the module.
std::shared_ptr< WProperties > m_infoProperties
The property object for the module containing only module whose purpose is "PV_PURPOSE_INFORMNATION".
void ready()
Call this whenever your module is ready and can react on property changes.
WConditionSet m_moduleState
The internal state of the module.
virtual void activate()
Callback for m_active.
WPropBool m_active
True whenever the module should be active.
std::shared_ptr< WProgressCombiner > m_progress
Progress indicator used as parent for all progress' of this module.
wlog::WStreamedLogger infoLog() const
Logger instance for comfortable info logging.
virtual void connectors()
Initialize connectors in this function.
void waitRestored()
This method waits for the module to be restored completely.
static boost::filesystem::path getAppPath()
The path where the binary file resides in.
This only is a 3d double vector.
Class managing progress inside of modules.
A named property class with a concrete type.
void sleep(const int32_t t) const
Sets thread asleep.
WBoolFlag m_shutdownFlag
Condition getting fired whenever the thread should quit.
@ PV_TRIGGER_TRIGGERED
Trigger property: got triggered.
@ PV_TRIGGER_READY
Trigger property: is ready to be triggered (again)
std::string PV_STRING
base type used for every WPVString
void addTo(WPropFilename prop)
Add the PC_PATHEXISTS constraint to the property.
void addTo(WPropSelection prop)
Add the PC_NOTEMPTY constraint to the property.
void addTo(WPropFilename prop)
Add the PC_PATHEXISTS constraint to the property.
void addTo(WPropSelection prop)
Add the PC_SELECTONLYONE constraint to the property.
std::string toString(const T &value)
Convert a given value to a string.