44 #include "DataControlPlugin.hh" 47 #include <ACG/QtWidgets/QtMaterialDialog.hh> 51 #include <ACG/Scenegraph/TranslationManipulatorNode.hh> 52 #include <ACG/Scenegraph/BoundingBoxNode.hh> 56 const ACG::Vec4f base_color (0.0f,0.0f,0.5f,1.0f);
57 const ACG::Vec4f source_color (0.5f,0.0f,0.0f,1.0f);
58 const ACG::Vec4f target_color (0.0f,0.5f,0.2f,1.0f);
80 advancedSettingsBtn_(0)
94 if ( ! OpenFlipper::Options::gui())
97 QMenu* contextMenu =
new QMenu(
"Object");
100 QIcon icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-hide-object.png");
101 QAction* hideAction =
new QAction(icon, tr(
"&Hide"),
this);
102 hideAction->setStatusTip(tr(
"Hide object"));
104 contextMenu->addAction(hideAction);
107 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-target-object.png");
115 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-source-object.png");
122 contextMenu->addSeparator();
125 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-delete-item.png");
134 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-material.png");
135 QAction* material =
new QAction(icon, tr(
"Material Properties"), 0);
139 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-copyToTargets-material.png");
140 QAction* copyMaterial =
new QAction(icon, tr(
"Copy Material Properties to Targeted Objects"), 0);
144 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-copy-material.png");
145 QAction* copyMaterialToClipboard =
new QAction(icon, tr(
"Copy Material Properties to Clipboard"), 0);
149 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-paste-material.png");
150 QAction* pasteMaterialFromClipboard =
new QAction(icon, tr(
"Paste Material Properties from Clipboard"), 0);
166 void DataControlPlugin::initializePlugin()
168 if ( ! OpenFlipper::Options::gui())
172 connect(
tool_ , SIGNAL( keyEvent( QKeyEvent* ) ),
174 QSize size(300, 300);
183 view_->QTreeView::resizeColumnToContents(1);
184 view_->QTreeView::resizeColumnToContents(2);
185 view_->QTreeView::resizeColumnToContents(3);
188 connect(
model_,SIGNAL(dataChangedInside(
int,
int,
const QVariant&) ),
191 connect(
model_,SIGNAL( moveBaseObject(
int,
int) ),
194 connect(
view_,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
197 connect(
tool_->notSelected, SIGNAL(toggled (
bool ) ),
199 connect(
tool_->sourceSelected, SIGNAL(toggled (
bool ) ),
201 connect(
tool_->targetSelected, SIGNAL(toggled (
bool ) ),
207 viewHeader_->setContextMenuPolicy(Qt::CustomContextMenu);
210 connect(
viewHeader_, SIGNAL(customContextMenuRequested (
const QPoint & ) ),
213 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-toolbox.png");
215 QWidget *headerAreaWidget =
new QWidget();
218 advancedSettingsBtn_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"preferences.png"));
222 QHBoxLayout *hl =
new QHBoxLayout;
225 hl->setContentsMargins(8, 0, 0, 0);
226 headerAreaWidget->setLayout(hl);
228 QMenu *menu =
new QMenu();
229 menu->addAction(
tool_->lightSources);
230 menu->addAction(
tool_->notSelected);
231 menu->addAction(
tool_->sourceSelected);
232 menu->addAction(
tool_->targetSelected);
235 emit addToolbox(
"Data Control",
tool_, toolIcon_, headerAreaWidget);
246 int selectedRows = _lst.size();
249 for(
int i = 0 ; i < selectedRows ; ++i)
266 if ( ! OpenFlipper::Options::gui())
286 if (item->
source() !=
object->source())
288 else if (item->
target() !=
object->target())
298 OpenFlipper::Options::blockSceneGraphUpdates();
299 OpenFlipper::Options::redrawDisabled(
true);
322 OpenFlipper::Options::unblockSceneGraphUpdates();
323 OpenFlipper::Options::redrawDisabled(
false);
336 if ( ! OpenFlipper::Options::gui())
350 OpenFlipper::Options::blockSceneGraphUpdates();
351 OpenFlipper::Options::redrawDisabled(
true);
378 OpenFlipper::Options::unblockSceneGraphUpdates();
379 OpenFlipper::Options::redrawDisabled(
false);
399 if ( ! OpenFlipper::Options::gui())
414 if ( ! OpenFlipper::Options::gui())
426 view_->resizeColumnToContents(0);
449 if ( ! OpenFlipper::Options::gui())
464 if ( _event->modifiers() == Qt::ControlModifier ) {
465 switch (_event->key()) {
474 switch (_event->key()) {
475 case Qt::Key_Delete :
504 obj->
setName( _value.toString() );
509 obj->
visible( _value.toBool() );
515 obj->
source( _value.toBool() );
522 obj->
target( _value.toBool() );
558 emit deleteObject( oldParent->
id() );
568 for(
int i = 0; i < rows; ++i) {
592 if ( _ini.
section_exists(
"BoundingBox" ) && OpenFlipper::Options::gui() )
595 if (_ini.
get_entry(value,
"BoundingBox",
"notSelected"))
596 tool_->notSelected->setChecked (value);
597 if (_ini.
get_entry(value,
"BoundingBox",
"sourceSelected"))
598 tool_->sourceSelected->setChecked (value);
599 if (_ini.
get_entry(value,
"BoundingBox",
"targetSelected"))
600 tool_->targetSelected->setChecked (value);
607 QStringList groupNames;
610 QStringList rootGroup;
613 _ini.
get_entry(groupNames,
"Groups",
"groups");
616 _ini.
get_entry(rootGroup,
"Groups",
"rootGroup");
619 QVector< BaseObject* > groups;
622 while ( rootGroup.size() > 0 ) {
623 QString current = rootGroup[0];
624 rootGroup.removeFirst();
626 QStringList groupChildren;
627 QStringList elementChildren;
629 _ini.
get_entry(elementChildren ,current,
"children");
630 _ini.
get_entry(groupChildren ,current,
"subgroups");
635 if ( _ini.
get_entry(parentName,current,
"parent") ) {
637 if ( parentItem == 0 )
642 rootGroup << groupChildren;
655 int p = groups.indexOf( group->
parent() );
659 groups.push_back( group );
663 for (
int i = 0 ; i < elementChildren.size() ; ++i ) {
681 std::queue< BaseObject* > children;
684 std::vector< BaseObject* > groups;
687 while ( ! children.empty() ) {
691 for (
int i = 0 ; i < item->
childCount(); ++i )
693 children.push( item->
child(i) );
696 groups.push_back(item);
700 QStringList groupNames;
703 QStringList rootGroup;
705 for ( uint i = 0 ; i < groups.size() ; ++i ) {
706 groupNames.push_back( groups[i]->
name() );
715 rootGroup.push_back( groups[i]->
name() );
718 QStringList groupchildren;
719 QStringList elementchildren;
720 for (
int j = 0 ; j < groups[i]->childCount(); ++j ) {
721 if ( groups[i]->child(j)->dataType(
DATA_GROUP) )
722 groupchildren.push_back( groups[i]->child(j)->name() );
724 elementchildren.push_back( groups[i]->child(j)->
name() );
728 _ini.
add_entry(groups[i]->
name(),
"children",elementchildren);
732 _ini.
add_entry(
"Groups",
"groups",groupNames);
735 _ini.
add_entry(
"Groups",
"rootGroup",rootGroup);
737 if ( OpenFlipper::Options::gui() ) {
739 _ini.
add_entry(
"BoundingBox",
"notSelected",
tool_->notSelected->isChecked ());
740 _ini.
add_entry(
"BoundingBox",
"sourceSelected",
tool_->sourceSelected->isChecked ());
741 _ini.
add_entry(
"BoundingBox",
"targetSelected",
tool_->targetSelected->isChecked ());
760 QList< BaseObject* > children = _obj->
getLeafs();
761 bool changed =
false;
769 for (
int i=0; i < children.size(); i++)
770 value |= children[i]->visible();
780 for (
int i=0; i < children.size(); i++){
781 value |= children[i]->source();
784 if (_obj->
source() != value){
792 for (
int i=0; i < children.size(); i++){
793 value |= children[i]->target();
796 if (_obj->
target() != value){
881 if (
tool_->notSelected->isChecked () ||
882 (_obj->
source () &&
tool_->sourceSelected->isChecked ()) ||
883 (_obj->
target () &&
tool_->targetSelected->isChecked ()))
889 if (_obj->
source () &&
tool_->sourceSelected->isChecked ())
890 color += source_color;
892 if (_obj->
target () &&
tool_->targetSelected->isChecked ())
893 color += target_color;
908 _ini.
add_entry(
"BoundingBox",
"notSelected",
tool_->notSelected->isChecked ());
909 _ini.
add_entry(
"BoundingBox",
"sourceSelected",
tool_->sourceSelected->isChecked ());
910 _ini.
add_entry(
"BoundingBox",
"targetSelected",
tool_->targetSelected->isChecked ());
918 void DataControlPlugin::slotObjectUpdated(
int _identifier,
const UpdateType& _type )
void slotKeyEvent(QKeyEvent *_event)
a key event occurred
DataType dataType()
dataType
void slotVisibilityChanged(int _identifier)
Update the model if the visibility of an object changed.
void propagateUpwards(BaseObject *_obj, int _column)
Recursively update a column up to the root of the tree.
void saveIniFileOptions(INIFile &_ini)
Save groups to ini file.
QList< BaseObject *> getLeafs()
get all leafes of the tree below this object ( These will be all visible objects ) ...
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
BaseObject * child(int row)
return a child
void slotBoundingBoxChange()
Bounding box selection changed.
int columnFromGUI_
Gets called when the data in the table has changed.
void loadIniFileOptionsLast(INIFile &_ini)
Load Groups from ini file.
int childCount() const
get the number of children
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
DefaultObjectMarker objectMarker
Default marker to visualize "source" and "target" object flags.
int onlyUp_
Gets called when the data in the table has changed.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
QHeaderView * viewHeader_
Pointer to the header to the view widget.
void slotContextMenuTarget()
Target Selection.
void slotCopyMaterialToTargeted()
Called by the popup menu to copy material properties.
void objectDeleted(int _id)
an object was deleted. delete it internally
QAction * targetAction_
Hide an object.
QModelIndex parent(const QModelIndex &_index) const
Get the parent ModelIndex.
void slotObjectPropertiesChanged(int _identifier)
Update the model if properties of an object changed.
bool getObject(const int _identifier, BaseObject *&_object)
Get the object which has the given identifier.
BaseObject *& objectRoot()
Get the root of the object structure.
const DataType DATA_GROUP(1)
Items used for Grouping.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
DataControlPlugin()
Constructor.
void slotCopyMaterialToClipboard()
Called by the popup menu to copy material properties to clipboard.
void setAllTarget()
Makes all available objects target.
QAction * removeAction_
Hide an object.
void showReducedUi(bool reduced)
Show or hide the extended ui interface in the datacontrol toolbox.
void slotDataChanged(int _id, int _column, const QVariant &_value)
Gets called when the data in the table has changed.
TreeItem * getItem(const QModelIndex &_index) const
Get the TreeItem corresponding to a given ModelIndex.
QAction * sourceAction_
Hide an object.
void slotHeaderCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeViews header.
BaseObject * childExists(int _objectId)
Check if the element exists in the subtree of this element.
bool dataType(DataType _type) const
QToolButton * advancedSettingsBtn_
Hide an object.
void setDefaultViewObjectMarker(ViewObjectMarker *_marker)
std::vector< int > IdList
Standard Type for id Lists used for scripting.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
TreeModel * model_
The Treemodel organizing the data.
QModelIndex index(int _row, int _column, const QModelIndex &_parent=QModelIndex()) const
Get the ModelIndex at given row,column.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
QTreeView * view_
Tree view.
BoundingBoxNode * boundingBoxNode()
get a pointer to the bounding box node
void setParent(BaseObject *_parent)
Set the parent pointer.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
void setViewObjectMarker(ViewObjectMarker *_marker)
void slotMoveBaseObject(int _id, int _newParentId)
Gets called when an object was moved via drag n drop.
void slotContextMenuRemove()
Remove Selected Item.
void slotCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeView.
QString name()
Name of the Plugin.
void set_status(StatusMode _s)
Set the status of this node.
DatacontrolToolboxWidget * tool_
Widget for Toolbox.
void fileOpened(int _id)
Update the model if a file has been opened.
bool isGroup() const
Check if object is a group.
void objectDeleted(int _id)
The object with the given id has been deleted. delete it from the internal tree.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
void slotContextMenuSource()
Source Selection.
int onlyDown_
Gets called when the data in the table has changed.
void objectChanged(int _id)
The object with the given id has been changed. Check if model also has to be changed.
void slotShowLightSources()
Index where a popup has been opened.
void slotObjectsGrouped(IdList _lst)
update objects when they have been grouped
void slotContextMenuHide()
Hide an object.
Class for the handling of simple configuration files.
void set_base_color(const Vec4f &_c)
set the base color ( Same as set_emission(const Vec4f& _c) )
void saveOnExit(INIFile &_ini)
Save settings before application is closed.
virtual bool visible()
return if object is visible
void slotObjectSelectionChanged(int _identifier)
update drawing of objects when the active object changed
int rowCount(const QModelIndex &_parent=QModelIndex()) const
get the number of rows
void addedEmptyObject(int _id)
Update the model if an empty object has been added.
void slotMaterialProperties()
Called by the popup menu to set material properties.
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
void propagateDownwards(BaseObject *_obj, int _column)
Recursively update a column up to the root of the tree.
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
void updateBoundingBox(BaseObjectData *_obj)
Updates bounding box.
void slotPasteMaterialFromClipboard()
Called by the popup menu to paste material properties from clipboard.
void pluginsInitialized()
Plugin initialization.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
Hide this node, but draw children.
int addEmptyGroup(QString _groupName="", int _parentGroupId=0)
Create new empty group.
void slotPopupRemove()
Called by the popup menu to remove an object/group.