50 #include "DataControlPlugin.hh"
52 #if QT_VERSION >= 0x050000
57 #include <ACG/QtWidgets/QtMaterialDialog.hh>
63 const ACG::Vec4f base_color (0.0f,0.0f,0.5f,1.0f);
64 const ACG::Vec4f source_color (0.5f,0.0f,0.0f,1.0f);
65 const ACG::Vec4f target_color (0.0f,0.5f,0.2f,1.0f);
87 advancedSettingsBtn_(0)
101 if ( ! OpenFlipper::Options::gui())
104 QMenu* contextMenu =
new QMenu(
"Object");
107 QIcon icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-hide-object.png");
108 QAction* hideAction =
new QAction(icon, tr(
"&Hide"),
this);
109 hideAction->setStatusTip(tr(
"Hide object"));
111 contextMenu->addAction(hideAction);
114 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-target-object.png");
122 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-source-object.png");
129 contextMenu->addSeparator();
132 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-delete-item.png");
141 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-material.png");
142 QAction* material =
new QAction(icon, tr(
"Material Properties"), 0);
146 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-copyToTargets-material.png");
147 QAction* copyMaterial =
new QAction(icon, tr(
"Copy Material Properties to Targeted Objects"), 0);
151 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-copy-material.png");
152 QAction* copyMaterialToClipboard =
new QAction(icon, tr(
"Copy Material Properties to Clipboard"), 0);
156 icon = QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-paste-material.png");
157 QAction* pasteMaterialFromClipboard =
new QAction(icon, tr(
"Paste Material Properties from Clipboard"), 0);
173 void DataControlPlugin::initializePlugin()
175 if ( ! OpenFlipper::Options::gui())
179 connect(
tool_ , SIGNAL( keyEvent( QKeyEvent* ) ),
181 QSize size(300, 300);
190 view_->QTreeView::resizeColumnToContents(1);
191 view_->QTreeView::resizeColumnToContents(2);
192 view_->QTreeView::resizeColumnToContents(3);
195 connect(
model_,SIGNAL(dataChangedInside(
int,
int,
const QVariant&) ),
198 connect(
model_,SIGNAL( moveBaseObject(
int,
int) ),
201 connect(
view_,SIGNAL(customContextMenuRequested (
const QPoint & ) ),
204 connect(
tool_->notSelected, SIGNAL(toggled (
bool ) ),
206 connect(
tool_->sourceSelected, SIGNAL(toggled (
bool ) ),
208 connect(
tool_->targetSelected, SIGNAL(toggled (
bool ) ),
213 viewHeader_->setContextMenuPolicy(Qt::CustomContextMenu);
216 connect(
viewHeader_, SIGNAL(customContextMenuRequested (
const QPoint & ) ),
219 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-toolbox.png");
221 QWidget *headerAreaWidget =
new QWidget();
224 advancedSettingsBtn_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"preferences.png"));
228 QHBoxLayout *hl =
new QHBoxLayout;
231 hl->setContentsMargins(8, 0, 0, 0);
232 headerAreaWidget->setLayout(hl);
234 QMenu *menu =
new QMenu();
235 menu->addAction(
tool_->lightSources);
236 menu->addAction(
tool_->notSelected);
237 menu->addAction(
tool_->sourceSelected);
238 menu->addAction(
tool_->targetSelected);
241 emit addToolbox(
"Data Control",
tool_, toolIcon_, headerAreaWidget);
252 if ( ! OpenFlipper::Options::gui())
272 if (item->
source() !=
object->source())
274 else if (item->
target() !=
object->target())
284 OpenFlipper::Options::blockSceneGraphUpdates();
285 OpenFlipper::Options::redrawDisabled(
true);
308 OpenFlipper::Options::unblockSceneGraphUpdates();
309 OpenFlipper::Options::redrawDisabled(
false);
322 if ( ! OpenFlipper::Options::gui())
336 OpenFlipper::Options::blockSceneGraphUpdates();
337 OpenFlipper::Options::redrawDisabled(
true);
364 OpenFlipper::Options::unblockSceneGraphUpdates();
365 OpenFlipper::Options::redrawDisabled(
false);
385 if ( ! OpenFlipper::Options::gui())
400 if ( ! OpenFlipper::Options::gui())
412 view_->resizeColumnToContents(0);
435 if ( ! OpenFlipper::Options::gui())
450 if ( _event->modifiers() == Qt::ControlModifier ) {
451 switch (_event->key()) {
460 switch (_event->key()) {
461 case Qt::Key_Delete :
490 obj->
setName( _value.toString() );
495 obj->
visible( _value.toBool() );
501 obj->
source( _value.toBool() );
508 obj->
target( _value.toBool() );
544 emit deleteObject( oldParent->
id() );
554 for(
int i = 0; i < rows; ++i) {
578 if ( _ini.
section_exists(
"BoundingBox" ) && OpenFlipper::Options::gui() )
581 if (_ini.
get_entry(value,
"BoundingBox",
"notSelected"))
582 tool_->notSelected->setChecked (value);
583 if (_ini.
get_entry(value,
"BoundingBox",
"sourceSelected"))
584 tool_->sourceSelected->setChecked (value);
585 if (_ini.
get_entry(value,
"BoundingBox",
"targetSelected"))
586 tool_->targetSelected->setChecked (value);
593 QStringList groupNames;
596 QStringList rootGroup;
599 _ini.
get_entry(groupNames,
"Groups",
"groups");
602 _ini.
get_entry(rootGroup,
"Groups",
"rootGroup");
605 QVector< BaseObject* > groups;
608 while ( rootGroup.size() > 0 ) {
609 QString current = rootGroup[0];
610 rootGroup.removeFirst();
612 QStringList groupChildren;
613 QStringList elementChildren;
615 _ini.
get_entry(elementChildren ,current,
"children");
616 _ini.
get_entry(groupChildren ,current,
"subgroups");
621 if ( _ini.
get_entry(parentName,current,
"parent") ) {
623 if ( parentItem == 0 )
628 rootGroup << groupChildren;
641 int p = groups.indexOf( group->
parent() );
645 groups.push_back( group );
649 for (
int i = 0 ; i < elementChildren.size() ; ++i ) {
667 std::queue< BaseObject* > children;
670 std::vector< BaseObject* > groups;
673 while ( ! children.empty() ) {
677 for (
int i = 0 ; i < item->
childCount(); ++i )
679 children.push( item->
child(i) );
682 groups.push_back(item);
686 QStringList groupNames;
689 QStringList rootGroup;
691 for ( uint i = 0 ; i < groups.size() ; ++i ) {
692 groupNames.push_back( groups[i]->
name() );
701 rootGroup.push_back( groups[i]->
name() );
704 QStringList groupchildren;
705 QStringList elementchildren;
706 for (
int j = 0 ; j < groups[i]->childCount(); ++j ) {
707 if ( groups[i]->child(j)->dataType(
DATA_GROUP) )
708 groupchildren.push_back( groups[i]->child(j)->name() );
710 elementchildren.push_back( groups[i]->child(j)->
name() );
714 _ini.
add_entry(groups[i]->
name(),
"children",elementchildren);
718 _ini.
add_entry(
"Groups",
"groups",groupNames);
721 _ini.
add_entry(
"Groups",
"rootGroup",rootGroup);
723 if ( OpenFlipper::Options::gui() ) {
725 _ini.
add_entry(
"BoundingBox",
"notSelected",
tool_->notSelected->isChecked ());
726 _ini.
add_entry(
"BoundingBox",
"sourceSelected",
tool_->sourceSelected->isChecked ());
727 _ini.
add_entry(
"BoundingBox",
"targetSelected",
tool_->targetSelected->isChecked ());
746 QList< BaseObject* > children = _obj->
getLeafs();
747 bool changed =
false;
755 for (
int i=0; i < children.size(); i++)
756 value |= children[i]->visible();
766 for (
int i=0; i < children.size(); i++){
767 value |= children[i]->source();
770 if (_obj->
source() != value){
778 for (
int i=0; i < children.size(); i++){
779 value |= children[i]->target();
782 if (_obj->
target() != value){
867 if (
tool_->notSelected->isChecked () ||
868 (_obj->
source () &&
tool_->sourceSelected->isChecked ()) ||
869 (_obj->
target () &&
tool_->targetSelected->isChecked ()))
875 if (_obj->
source () &&
tool_->sourceSelected->isChecked ())
876 color += source_color;
878 if (_obj->
target () &&
tool_->targetSelected->isChecked ())
879 color += target_color;
894 _ini.
add_entry(
"BoundingBox",
"notSelected",
tool_->notSelected->isChecked ());
895 _ini.
add_entry(
"BoundingBox",
"sourceSelected",
tool_->sourceSelected->isChecked ());
896 _ini.
add_entry(
"BoundingBox",
"targetSelected",
tool_->targetSelected->isChecked ());
904 void DataControlPlugin::slotObjectUpdated(
int _identifier,
const UpdateType& _type )
918 #if QT_VERSION < 0x050000
void updateBoundingBox(BaseObjectData *_obj)
Updates bounding box.
void setViewObjectMarker(ViewObjectMarker *_marker)
void slotObjectPropertiesChanged(int _identifier)
Update the model if properties of an object changed.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
DataType dataType()
dataType
void slotCopyMaterialToTargeted()
Called by the popup menu to copy material properties.
void addedEmptyObject(int _id)
Update the model if an empty object has been added.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
TreeModel * model_
The Treemodel organizing the data.
QTreeView * view_
Tree view.
void slotContextMenuSource()
Source Selection.
bool getObject(int _identifier, BSplineCurveObject *&_object)
void set_base_color(const Vec4f &_c)
set the base color
const DataType DATA_GROUP(1)
Items used for Grouping.
void slotCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeView.
QModelIndex parent(const QModelIndex &_index) const
Get the parent ModelIndex.
void fileOpened(int _id)
Update the model if a file has been opened.
void slotHeaderCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeViews header.
QAction * targetAction_
Hide an object.
virtual bool visible()
return if object is visible
void slotMoveBaseObject(int _id, int _newParentId)
Gets called when an object was moved via drag n drop.
bool isGroup() const
Check if object is a group.
bool dataType(DataType _type) const
QAction * sourceAction_
Hide an object.
void slotKeyEvent(QKeyEvent *_event)
a key event occurred
int columnFromGUI_
Gets called when the data in the table has changed.
QModelIndex index(int _row, int _column, const QModelIndex &_parent=QModelIndex()) const
Get the ModelIndex at given row,column.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
Hide this node, but draw children.
QToolButton * advancedSettingsBtn_
Hide an object.
void objectChanged(int _id)
The object with the given id has been changed. Check if model also has to be changed.
void set_status(StatusMode _s)
Set the status of this node.
Class for the handling of simple configuration files.
int onlyUp_
Gets called when the data in the table has changed.
DataControlPlugin()
Constructor.
int rowCount(const QModelIndex &_parent=QModelIndex()) const
get the number of rows
void slotVisibilityChanged(int _identifier)
Update the model if the visibility of an object changed.
void slotPasteMaterialFromClipboard()
Called by the popup menu to paste material properties from clipboard.
void slotCopyMaterialToClipboard()
Called by the popup menu to copy material properties to clipboard.
QAction * removeAction_
Hide an object.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
void setParent(BaseObject *_parent)
Set the parent pointer.
BaseObject * childExists(int _objectId)
Check if the element exists in the subtree of this element.
void slotMaterialProperties()
Called by the popup menu to set material properties.
BaseObject *& objectRoot()
Get the root of the object structure.
DefaultObjectMarker objectMarker
Default marker to visualize "source" and "target" object flags.
int addEmptyGroup(QString _groupName="", int _parentGroupId=0)
Create new empty group.
QString name()
Name of the Plugin.
BoundingBoxNode * boundingBoxNode()
get a pointer to the bounding box node
void loadIniFileOptionsLast(INIFile &_ini)
Load Groups from ini file.
void slotContextMenuTarget()
Target Selection.
QList< BaseObject * > getLeafs()
get all leafes of the tree below this object ( These will be all visible objects ) ...
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
void slotDataChanged(int _id, int _column, const QVariant &_value)
Gets called when the data in the table has changed.
void setDefaultViewObjectMarker(ViewObjectMarker *_marker)
void setAllTarget()
Makes all available objects target.
QHeaderView * viewHeader_
Pointer to the header to the view widget.
void slotPopupRemove()
Called by the popup menu to remove an object/group.
DatacontrolToolboxWidget * tool_
Widget for Toolbox.
void propagateDownwards(BaseObject *_obj, int _column)
Recursively update a column up to the root of the tree.
The Menu will be shown when an object was picked.
void saveIniFileOptions(INIFile &_ini)
Save groups to ini file.
void showReducedUi(bool reduced)
int onlyDown_
Gets called when the data in the table has changed.
int childCount() const
get the number of children
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
void slotShowLightSources()
Index where a popup has been opened.
void objectDeleted(int _id)
The object with the given id has been deleted. delete it from the internal tree.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
void slotObjectSelectionChanged(int _identifier)
update drawing of objects when the active object changed
void saveOnExit(INIFile &_ini)
Save settings before application is closed.
BaseObject * child(int row)
return a child
void slotContextMenuHide()
Hide an object.
TreeItem * getItem(const QModelIndex &_index) const
Get the TreeItem corresponding to a given ModelIndex.
void slotBoundingBoxChange()
Bounding box selection changed.
void objectDeleted(int _id)
an object was deleted. delete it internally
void propagateUpwards(BaseObject *_obj, int _column)
Recursively update a column up to the root of the tree.
void slotContextMenuRemove()
Remove Selected Item.
void pluginsInitialized()
Plugin initialization.