44#include "DataControlPlugin.hh"
47#include <ACG/QtWidgets/QtMaterialDialog.hh>
51#include <ACG/Scenegraph/TranslationManipulatorNode.hh>
52#include <ACG/Scenegraph/BoundingBoxNode.hh>
56const ACG::Vec4f base_color (0.0f,0.0f,0.5f,1.0f);
57const ACG::Vec4f source_color (0.5f,0.0f,0.0f,1.0f);
58const ACG::Vec4f target_color (0.0f,0.5f,0.2f,1.0f);
67 MeshDialogLayout_(nullptr),
77 targetAction_(nullptr),
78 sourceAction_(nullptr),
79 removeAction_(nullptr),
81 copyMaterial_(nullptr),
82 copyMaterialToClipboard_(nullptr),
83 pasteMaterialFromClipboard_(nullptr),
84 advancedSettingsBtn_(nullptr)
98 if ( ! OpenFlipper::Options::gui())
101 QMenu* contextMenu =
new QMenu(
"Object");
104 QIcon icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-hide-object.png");
105 QAction* hideAction =
new QAction(icon, tr(
"&Hide"),
this);
106 hideAction->setStatusTip(tr(
"Hide object"));
108 contextMenu->addAction(hideAction);
111 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-target-object.png");
119 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-source-object.png");
126 contextMenu->addSeparator();
129 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-delete-item.png");
138 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-material.png");
139 material_ =
new QAction(icon, tr(
"Material Properties"), 0);
143 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-copyToTargets-material.png");
144 copyMaterial_ =
new QAction(icon, tr(
"Copy Material Properties to Targeted Objects"), 0);
148 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-copy-material.png");
153 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-paste-material.png");
170void DataControlPlugin::initializePlugin()
172 if ( ! OpenFlipper::Options::gui())
176 connect(
tool_ , SIGNAL( keyEvent( QKeyEvent* ) ),
178 QSize size(300, 300);
187 view_->QTreeView::resizeColumnToContents(1);
188 view_->QTreeView::resizeColumnToContents(2);
189 view_->QTreeView::resizeColumnToContents(3);
192 connect(
model_,SIGNAL(dataChangedInside(
int,
int,
const QVariant&) ),
195 connect(
model_,SIGNAL( moveBaseObject(
int,
int) ),
198 connect(
view_,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
201 connect(
tool_->notSelected, SIGNAL(toggled (
bool ) ),
203 connect(
tool_->sourceSelected, SIGNAL(toggled (
bool ) ),
205 connect(
tool_->targetSelected, SIGNAL(toggled (
bool ) ),
211 viewHeader_->setContextMenuPolicy(Qt::CustomContextMenu);
214 connect(
viewHeader_, SIGNAL(customContextMenuRequested (
const QPoint & ) ),
217 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-toolbox.png");
219 QWidget *headerAreaWidget =
new QWidget();
222 advancedSettingsBtn_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"preferences.png"));
226 QHBoxLayout *hl =
new QHBoxLayout;
229 hl->setContentsMargins(8, 0, 0, 0);
230 headerAreaWidget->setLayout(hl);
232 QMenu *menu =
new QMenu();
233 menu->addAction(
tool_->lightSources);
234 menu->addAction(
tool_->notSelected);
235 menu->addAction(
tool_->sourceSelected);
236 menu->addAction(
tool_->targetSelected);
239 emit addToolbox(
"Data Control",
tool_, toolIcon_, headerAreaWidget);
260 int selectedRows = _lst.size();
263 for(
int i = 0 ; i < selectedRows ; ++i)
280 if ( ! OpenFlipper::Options::gui())
312 OpenFlipper::Options::blockSceneGraphUpdates();
313 OpenFlipper::Options::redrawDisabled(
true);
336 OpenFlipper::Options::unblockSceneGraphUpdates();
337 OpenFlipper::Options::redrawDisabled(
false);
350 if ( ! OpenFlipper::Options::gui())
364 OpenFlipper::Options::blockSceneGraphUpdates();
365 OpenFlipper::Options::redrawDisabled(
true);
392 OpenFlipper::Options::unblockSceneGraphUpdates();
393 OpenFlipper::Options::redrawDisabled(
false);
413 if ( ! OpenFlipper::Options::gui())
428 if ( ! OpenFlipper::Options::gui())
440 view_->resizeColumnToContents(0);
463 if ( ! OpenFlipper::Options::gui())
478 if ( _event->modifiers() == Qt::ControlModifier ) {
479 switch (_event->key()) {
488 switch (_event->key()) {
489 case Qt::Key_Delete :
518 obj->
setName( _value.toString() );
523 obj->
visible( _value.toBool() );
529 obj->
source( _value.toBool() );
536 obj->
target( _value.toBool() );
572 emit deleteObject( oldParent->
id() );
582 for(
int i = 0; i < rows; ++i) {
606 if ( _ini.
section_exists(
"BoundingBox" ) && OpenFlipper::Options::gui() )
609 if (_ini.
get_entry(value,
"BoundingBox",
"notSelected"))
610 tool_->notSelected->setChecked (value);
611 if (_ini.
get_entry(value,
"BoundingBox",
"sourceSelected"))
612 tool_->sourceSelected->setChecked (value);
613 if (_ini.
get_entry(value,
"BoundingBox",
"targetSelected"))
614 tool_->targetSelected->setChecked (value);
621 QStringList groupNames;
624 QStringList rootGroup;
627 _ini.
get_entry(groupNames,
"Groups",
"groups");
630 _ini.
get_entry(rootGroup,
"Groups",
"rootGroup");
633 QVector< BaseObject* > groups;
636 while ( rootGroup.size() > 0 ) {
637 QString current = rootGroup[0];
638 rootGroup.removeFirst();
640 QStringList groupChildren;
641 QStringList elementChildren;
643 _ini.
get_entry(elementChildren ,current,
"children");
644 _ini.
get_entry(groupChildren ,current,
"subgroups");
649 if ( _ini.
get_entry(parentName,current,
"parent") ) {
651 if ( parentItem == 0 )
656 rootGroup << groupChildren;
669 int p = groups.indexOf( group->
parent() );
673 groups.push_back( group );
677 for (
int i = 0 ; i < elementChildren.size() ; ++i ) {
695 std::queue< BaseObject* > children;
698 std::vector< BaseObject* > groups;
701 while ( ! children.empty() ) {
705 for (
int i = 0 ; i < item->
childCount(); ++i )
707 children.push( item->
child(i) );
710 groups.push_back(item);
714 QStringList groupNames;
717 QStringList rootGroup;
719 for ( uint i = 0 ; i < groups.size() ; ++i ) {
720 groupNames.push_back( groups[i]->
name() );
729 rootGroup.push_back( groups[i]->
name() );
732 QStringList groupchildren;
733 QStringList elementchildren;
734 for (
int j = 0 ; j < groups[i]->childCount(); ++j ) {
736 groupchildren.push_back( groups[i]->child(j)->
name() );
738 elementchildren.push_back( groups[i]->child(j)->
name() );
742 _ini.
add_entry(groups[i]->
name(),
"children",elementchildren);
746 _ini.
add_entry(
"Groups",
"groups",groupNames);
749 _ini.
add_entry(
"Groups",
"rootGroup",rootGroup);
751 if ( OpenFlipper::Options::gui() ) {
753 _ini.
add_entry(
"BoundingBox",
"notSelected",
tool_->notSelected->isChecked ());
754 _ini.
add_entry(
"BoundingBox",
"sourceSelected",
tool_->sourceSelected->isChecked ());
755 _ini.
add_entry(
"BoundingBox",
"targetSelected",
tool_->targetSelected->isChecked ());
774 QList< BaseObject* > children = _obj->
getLeafs();
775 bool changed =
false;
783 for (
int i=0; i < children.size(); i++)
784 value |= children[i]->visible();
794 for (
int i=0; i < children.size(); i++){
795 value |= children[i]->source();
798 if (_obj->
source() != value){
806 for (
int i=0; i < children.size(); i++){
807 value |= children[i]->target();
810 if (_obj->
target() != value){
895 if (
tool_->notSelected->isChecked () ||
896 (_obj->
source () &&
tool_->sourceSelected->isChecked ()) ||
897 (_obj->
target () &&
tool_->targetSelected->isChecked ()))
903 if (_obj->
source () &&
tool_->sourceSelected->isChecked ())
904 color += source_color;
906 if (_obj->
target () &&
tool_->targetSelected->isChecked ())
907 color += target_color;
922 _ini.
add_entry(
"BoundingBox",
"notSelected",
tool_->notSelected->isChecked ());
923 _ini.
add_entry(
"BoundingBox",
"sourceSelected",
tool_->sourceSelected->isChecked ());
924 _ini.
add_entry(
"BoundingBox",
"targetSelected",
tool_->targetSelected->isChecked ());
932void DataControlPlugin::slotObjectUpdated(
int _identifier,
const UpdateType& _type )
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
const DataType DATA_GROUP(1)
Items used for Grouping.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
@ HideNode
Hide this node, but draw children.
@ Active
Draw node & children.
void set_status(StatusMode _s)
Set the status of this node.
void set_base_color(const Vec4f &_c)
set the base color ( Same as set_emission(const Vec4f& _c) )
BoundingBoxNode * boundingBoxNode()
get a pointer to the bounding box node
int childCount() const
get the number of children
QList< BaseObject * > getLeafs()
get all leafes of the tree below this object ( These will be all visible objects )
BaseObject * parent()
Get the parent item ( 0 if rootitem )
void setParent(BaseObject *_parent)
Set the parent pointer.
BaseObject * childExists(int _objectId)
Check if the element exists in the subtree of this element.
bool dataType(DataType _type) const
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
BaseObject * child(int row)
return a child
bool isGroup() const
Check if object is a group.
virtual bool visible()
return if object is visible
void slotKeyEvent(QKeyEvent *_event)
a key event occurred
void setAllTarget()
Makes all available objects target.
void slotCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeView.
void objectDeleted(int _id)
an object was deleted. delete it internally
DefaultObjectMarker objectMarker
Default marker to visualize "source" and "target" object flags.
void slotMoveBaseObject(int _id, int _newParentId)
Gets called when an object was moved via drag n drop.
void addedEmptyObject(int _id)
Update the model if an empty object has been added.
void slotShowLightSources()
Index where a popup has been opened.
DatacontrolToolboxWidget * tool_
Widget for Toolbox.
QAction * removeAction_
Hide an object.
QHeaderView * viewHeader_
Pointer to the header to the view widget.
QAction * targetAction_
Hide an object.
void slotMaterialProperties()
Called by the popup menu to set material properties.
void slotHeaderCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeViews header.
void slotContextMenuRemove()
Remove Selected Item.
void fileOpened(int _id)
Update the model if a file has been opened.
QToolButton * advancedSettingsBtn_
Hide an object.
void propagateDownwards(BaseObject *_obj, int _column)
Recursively update a column up to the root of the tree.
~DataControlPlugin()
Destructor.
void propagateUpwards(BaseObject *_obj, int _column)
Recursively update a column up to the root of the tree.
int columnFromGUI_
Gets called when the data in the table has changed.
void slotBoundingBoxChange()
Bounding box selection changed.
void pluginsInitialized()
Plugin initialization.
void saveIniFileOptions(INIFile &_ini)
Save groups to ini file.
QAction * material_
Hide an object.
QTreeView * view_
Tree view.
void slotVisibilityChanged(int _identifier)
Update the model if the visibility of an object changed.
void slotContextMenuSource()
Source Selection.
void slotPopupRemove()
Called by the popup menu to remove an object/group.
TreeModel * model_
The Treemodel organizing the data.
DataControlPlugin()
Constructor.
void slotObjectSelectionChanged(int _identifier)
update drawing of objects when the active object changed
void saveOnExit(INIFile &_ini)
Save settings before application is closed.
int onlyDown_
Gets called when the data in the table has changed.
void showReducedUi(bool reduced)
Show or hide the extended ui interface in the datacontrol toolbox.
QString name()
Name of the Plugin.
int onlyUp_
Gets called when the data in the table has changed.
QAction * pasteMaterialFromClipboard_
Hide an object.
void slotCopyMaterialToClipboard()
Called by the popup menu to copy material properties to clipboard.
QAction * copyMaterial_
Hide an object.
QAction * copyMaterialToClipboard_
Hide an object.
void updateBoundingBox(BaseObjectData *_obj)
Updates bounding box.
void slotCopyMaterialToTargeted()
Called by the popup menu to copy material properties.
void slotObjectsGrouped(IdList _lst)
update objects when they have been grouped
void slotObjectPropertiesChanged(int _identifier)
Update the model if properties of an object changed.
void loadIniFileOptionsLast(INIFile &_ini)
Load Groups from ini file.
int addEmptyGroup(QString _groupName="", int _parentGroupId=0)
Create new empty group.
void slotContextMenuTarget()
Target Selection.
QAction * sourceAction_
Hide an object.
void slotContextMenuHide()
Hide an object.
void slotPasteMaterialFromClipboard()
Called by the popup menu to paste material properties from clipboard.
DataType dataType(int objectId)
Get the DataType of a given object.
void slotDataChanged(int _id, int _column, const QVariant &_value)
Gets called when the data in the table has changed.
Class for the handling of simple configuration files.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
DataType dataType()
dataType
int rowCount(const QModelIndex &_parent=QModelIndex()) const
get the number of rows
void objectDeleted(int _id)
The object with the given id has been deleted. delete it from the internal tree.
QModelIndex parent(const QModelIndex &_index) const
Get the parent ModelIndex.
void objectChanged(int _id)
The object with the given id has been changed. Check if model also has to be changed.
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
TreeItem * getItem(const QModelIndex &_index) const
Get the TreeItem corresponding to a given ModelIndex.
QModelIndex index(int _row, int _column, const QModelIndex &_parent=QModelIndex()) const
Get the ModelIndex at given row,column.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(4))
Geometry updated.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
BaseObject *& objectRoot()
Get the root of the object structure.
void setDefaultViewObjectMarker(ViewObjectMarker *_marker)
ObjectRange objects(IteratorRestriction _restriction, DataType _dataType)
Iterable object range.
void setViewObjectMarker(ViewObjectMarker *_marker)