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 ) ),
214 viewHeader_->setContextMenuPolicy(Qt::CustomContextMenu);
217 connect(
viewHeader_, SIGNAL(customContextMenuRequested (
const QPoint & ) ),
220 toolIcon_ =
new QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"datacontrol-toolbox.png");
222 QWidget *headerAreaWidget =
new QWidget();
225 advancedSettingsBtn_->setIcon(QIcon(OpenFlipper::Options::iconDirStr()+OpenFlipper::Options::dirSeparator()+
"preferences.png"));
229 QHBoxLayout *hl =
new QHBoxLayout;
232 hl->setContentsMargins(8, 0, 0, 0);
233 headerAreaWidget->setLayout(hl);
235 QMenu *menu =
new QMenu();
236 menu->addAction(
tool_->lightSources);
237 menu->addAction(
tool_->notSelected);
238 menu->addAction(
tool_->sourceSelected);
239 menu->addAction(
tool_->targetSelected);
242 emit addToolbox(
"Data Control",
tool_, toolIcon_, headerAreaWidget);
253 int selectedRows = _lst.size();
256 for(
int i = 0 ; i < selectedRows ; ++i)
273 if ( ! OpenFlipper::Options::gui())
293 if (item->
source() !=
object->source())
295 else if (item->
target() !=
object->target())
305 OpenFlipper::Options::blockSceneGraphUpdates();
306 OpenFlipper::Options::redrawDisabled(
true);
329 OpenFlipper::Options::unblockSceneGraphUpdates();
330 OpenFlipper::Options::redrawDisabled(
false);
343 if ( ! OpenFlipper::Options::gui())
357 OpenFlipper::Options::blockSceneGraphUpdates();
358 OpenFlipper::Options::redrawDisabled(
true);
385 OpenFlipper::Options::unblockSceneGraphUpdates();
386 OpenFlipper::Options::redrawDisabled(
false);
406 if ( ! OpenFlipper::Options::gui())
421 if ( ! OpenFlipper::Options::gui())
433 view_->resizeColumnToContents(0);
456 if ( ! OpenFlipper::Options::gui())
471 if ( _event->modifiers() == Qt::ControlModifier ) {
472 switch (_event->key()) {
481 switch (_event->key()) {
482 case Qt::Key_Delete :
511 obj->
setName( _value.toString() );
516 obj->
visible( _value.toBool() );
522 obj->
source( _value.toBool() );
529 obj->
target( _value.toBool() );
565 emit deleteObject( oldParent->
id() );
575 for(
int i = 0; i < rows; ++i) {
599 if ( _ini.
section_exists(
"BoundingBox" ) && OpenFlipper::Options::gui() )
602 if (_ini.
get_entry(value,
"BoundingBox",
"notSelected"))
603 tool_->notSelected->setChecked (value);
604 if (_ini.
get_entry(value,
"BoundingBox",
"sourceSelected"))
605 tool_->sourceSelected->setChecked (value);
606 if (_ini.
get_entry(value,
"BoundingBox",
"targetSelected"))
607 tool_->targetSelected->setChecked (value);
614 QStringList groupNames;
617 QStringList rootGroup;
620 _ini.
get_entry(groupNames,
"Groups",
"groups");
623 _ini.
get_entry(rootGroup,
"Groups",
"rootGroup");
626 QVector< BaseObject* > groups;
629 while ( rootGroup.size() > 0 ) {
630 QString current = rootGroup[0];
631 rootGroup.removeFirst();
633 QStringList groupChildren;
634 QStringList elementChildren;
636 _ini.
get_entry(elementChildren ,current,
"children");
637 _ini.
get_entry(groupChildren ,current,
"subgroups");
642 if ( _ini.
get_entry(parentName,current,
"parent") ) {
644 if ( parentItem == 0 )
649 rootGroup << groupChildren;
662 int p = groups.indexOf( group->
parent() );
666 groups.push_back( group );
670 for (
int i = 0 ; i < elementChildren.size() ; ++i ) {
688 std::queue< BaseObject* > children;
691 std::vector< BaseObject* > groups;
694 while ( ! children.empty() ) {
698 for (
int i = 0 ; i < item->
childCount(); ++i )
700 children.push( item->
child(i) );
703 groups.push_back(item);
707 QStringList groupNames;
710 QStringList rootGroup;
712 for ( uint i = 0 ; i < groups.size() ; ++i ) {
713 groupNames.push_back( groups[i]->
name() );
722 rootGroup.push_back( groups[i]->
name() );
725 QStringList groupchildren;
726 QStringList elementchildren;
727 for (
int j = 0 ; j < groups[i]->childCount(); ++j ) {
728 if ( groups[i]->child(j)->dataType(
DATA_GROUP) )
729 groupchildren.push_back( groups[i]->child(j)->name() );
731 elementchildren.push_back( groups[i]->child(j)->
name() );
735 _ini.
add_entry(groups[i]->
name(),
"children",elementchildren);
739 _ini.
add_entry(
"Groups",
"groups",groupNames);
742 _ini.
add_entry(
"Groups",
"rootGroup",rootGroup);
744 if ( OpenFlipper::Options::gui() ) {
746 _ini.
add_entry(
"BoundingBox",
"notSelected",
tool_->notSelected->isChecked ());
747 _ini.
add_entry(
"BoundingBox",
"sourceSelected",
tool_->sourceSelected->isChecked ());
748 _ini.
add_entry(
"BoundingBox",
"targetSelected",
tool_->targetSelected->isChecked ());
767 QList< BaseObject* > children = _obj->
getLeafs();
768 bool changed =
false;
776 for (
int i=0; i < children.size(); i++)
777 value |= children[i]->visible();
787 for (
int i=0; i < children.size(); i++){
788 value |= children[i]->source();
791 if (_obj->
source() != value){
799 for (
int i=0; i < children.size(); i++){
800 value |= children[i]->target();
803 if (_obj->
target() != value){
888 if (
tool_->notSelected->isChecked () ||
889 (_obj->
source () &&
tool_->sourceSelected->isChecked ()) ||
890 (_obj->
target () &&
tool_->targetSelected->isChecked ()))
896 if (_obj->
source () &&
tool_->sourceSelected->isChecked ())
897 color += source_color;
899 if (_obj->
target () &&
tool_->targetSelected->isChecked ())
900 color += target_color;
915 _ini.
add_entry(
"BoundingBox",
"notSelected",
tool_->notSelected->isChecked ());
916 _ini.
add_entry(
"BoundingBox",
"sourceSelected",
tool_->sourceSelected->isChecked ());
917 _ini.
add_entry(
"BoundingBox",
"targetSelected",
tool_->targetSelected->isChecked ());
925 void DataControlPlugin::slotObjectUpdated(
int _identifier,
const UpdateType& _type )
939 #if QT_VERSION < 0x050000 void slotKeyEvent(QKeyEvent *_event)
a key event occurred
BaseObject *& objectRoot()
Get the root of the object structure.
QAction * targetAction_
Hide an object.
int rowCount(const QModelIndex &_parent=QModelIndex()) const
get the number of rows
void slotMaterialProperties()
Called by the popup menu to set material properties.
void pluginsInitialized()
Plugin initialization.
void slotCopyMaterialToTargeted()
Called by the popup menu to copy material properties.
void objectChanged(int _id)
The object with the given id has been changed. Check if model also has to be changed.
virtual bool visible()
return if object is visible
void slotObjectPropertiesChanged(int _identifier)
Update the model if properties of an object changed.
void saveOnExit(INIFile &_ini)
Save settings before application is closed.
void slotShowLightSources()
Index where a popup has been opened.
void saveIniFileOptions(INIFile &_ini)
Save groups to ini file.
bool getObject(int _identifier, BSplineCurveObject *&_object)
QToolButton * advancedSettingsBtn_
Hide an object.
void updateBoundingBox(BaseObjectData *_obj)
Updates bounding box.
void slotContextMenuHide()
Hide an object.
bool dataType(DataType _type) const
void set_base_color(const Vec4f &_c)
set the base color
The Menu will be shown when an object was picked.
int childCount() const
get the number of children
void slotDataChanged(int _id, int _column, const QVariant &_value)
Gets called when the data in the table has changed.
QAction * removeAction_
Hide an object.
void objectDeleted(int _id)
an object was deleted. delete it internally
BoundingBoxNode * boundingBoxNode()
get a pointer to the bounding box node
TreeModel * model_
The Treemodel organizing the data.
int onlyUp_
Gets called when the data in the table has changed.
void propagateDownwards(BaseObject *_obj, int _column)
Recursively update a column up to the root of the tree.
DefaultObjectMarker objectMarker
Default marker to visualize "source" and "target" object flags.
BaseObject * parent()
Get the parent item ( 0 if rootitem )
void setParent(BaseObject *_parent)
Set the parent pointer.
void slotHeaderCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeViews header.
void slotMoveBaseObject(int _id, int _newParentId)
Gets called when an object was moved via drag n drop.
DataControlPlugin()
Constructor.
bool get_entry(QString &_val, const QString &_section, const QString &_key) const
Access to a string entry.
void slotContextMenuTarget()
Target Selection.
bool contains(const UpdateType &_type) const
Check if this update contains the given UpdateType.
void setAllTarget()
Makes all available objects target.
void slotObjectSelectionChanged(int _identifier)
update drawing of objects when the active object changed
void slotPasteMaterialFromClipboard()
Called by the popup menu to paste material properties from clipboard.
const DataType DATA_ALL(UINT_MAX)
Identifier for all available objects.
void fileOpened(int _id)
Update the model if a file has been opened.
void showReducedUi(bool reduced)
bool section_exists(const QString &_section) const
Check if given section exists in the current INI file.
const UpdateType UPDATE_GEOMETRY(UpdateTypeSet(1)<< 2)
Geometry updated.
void setViewObjectMarker(ViewObjectMarker *_marker)
const DataType DATA_GROUP(1)
Items used for Grouping.
Class for the handling of simple configuration files.
QTreeView * view_
Tree view.
void slotVisibilityChanged(int _identifier)
Update the model if the visibility of an object changed.
BaseObject * child(int row)
return a child
void objectAdded(BaseObject *_object)
The object with the given id has been added. add it to the internal tree.
bool isGroup() const
Check if object is a group.
int onlyDown_
Gets called when the data in the table has changed.
std::vector< int > IdList
Standard Type for id Lists used for scripting.
QList< BaseObject * > getLeafs()
get all leafes of the tree below this object ( These will be all visible objects ) ...
void setDefaultViewObjectMarker(ViewObjectMarker *_marker)
QModelIndex parent(const QModelIndex &_index) const
Get the parent ModelIndex.
void slotCustomContextMenuRequested(const QPoint &_pos)
Display a custom context window for the TreeView.
QHeaderView * viewHeader_
Pointer to the header to the view widget.
int addEmptyGroup(QString _groupName="", int _parentGroupId=0)
Create new empty group.
void propagateUpwards(BaseObject *_obj, int _column)
Recursively update a column up to the root of the tree.
TreeItem * getItem(const QModelIndex &_index) const
Get the TreeItem corresponding to a given ModelIndex.
DatacontrolToolboxWidget * tool_
Widget for Toolbox.
QAction * sourceAction_
Hide an object.
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.
const UpdateType UPDATE_ALL(UpdateTypeSet(1))
Identifier for all updates.
void objectDeleted(int _id)
The object with the given id has been deleted. delete it from the internal tree.
void slotBoundingBoxChange()
Bounding box selection changed.
void slotObjectsGrouped(IdList _lst)
update objects when they have been grouped
void slotContextMenuSource()
Source Selection.
BaseObject * childExists(int _objectId)
Check if the element exists in the subtree of this element.
void addedEmptyObject(int _id)
Update the model if an empty object has been added.
Hide this node, but draw children.
void add_entry(const QString &_section, const QString &_key, const QString &_value)
Addition / modification of a string entry.
void set_status(StatusMode _s)
Set the status of this node.
void slotPopupRemove()
Called by the popup menu to remove an object/group.
void slotCopyMaterialToClipboard()
Called by the popup menu to copy material properties to clipboard.
void loadIniFileOptionsLast(INIFile &_ini)
Load Groups from ini file.
DLLEXPORT ObjectIterator objectsEnd()
Return Iterator to Object End.
virtual void setName(QString _name)
path to the file from which the object is loaded ( defaults to "." )
QString name()
Name of the Plugin.
DataType dataType()
dataType
void slotContextMenuRemove()
Remove Selected Item.