1 // Copyright (C) 2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "DependencyTree_Object.h"
23 #include <GeometryGUI.h>
24 #include <GEOM_BaseObject.hxx>
27 #include <SUIT_Session.h>
28 #include <SUIT_ResourceMgr.h>
29 #include <SalomeApp_Application.h>
30 #include <SalomeApp_Study.h>
38 DependencyTree_Object::DependencyTree_Object( const std::string& theEntry, QGraphicsItem* theParent )
39 :GraphicsView_Object( theParent ),
40 myIsMainObject( false ),
43 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
45 myColor = resMgr->colorValue( "Geometry", "dependency_tree_node_color", QColor( 62, 180, 238 ) );
46 mySelectColor = resMgr->colorValue( "Geometry", "dependency_tree_select_node_color", QColor( 237, 243, 58 ) );
47 myMainObjectColor = resMgr->colorValue( "Geometry", "dependency_tree_main_node_color", QColor( 238, 90, 125 ) );
49 myPolygonItem = new QGraphicsPolygonItem();
51 myPolygon << QPointF( -itemW, -itemH ) << QPointF( itemW, -itemH ) << QPointF( itemW, itemH )
52 << QPointF( -itemW, itemH ) << QPointF( -itemW, -itemH );
54 myPolygonItem->setPolygon( myPolygon );
55 myPolygonItem->setBrush( myColor );
56 myPolygonItem->setPen( getPen( myColor ) );
58 myTextItem = new QGraphicsSimpleTextItem();
60 textFont.setPointSize( itemH );
61 myTextItem->setFont( textFont );
66 addToGroup( myPolygonItem );
67 addToGroup( myTextItem );
70 DependencyTree_Object::~DependencyTree_Object()
74 //=================================================================================
75 // function : highlight()
76 // purpose : highlight current item
77 //=================================================================================
78 bool DependencyTree_Object::highlight( double theX, double theY )
80 if( !isHighlighted() ) {
81 QColor color = myPolygonItem->brush().color();
82 int saturation = ( color.saturation() - 100 ) > 10 ? color.saturation() - 100 : 10;
83 color.setHsv( color.hsvHue(), saturation, color.value() );
85 myPolygonItem->setBrush( color );
86 myPolygonItem->setPen( getPen( color ) );
89 myPolygonItem->setToolTip( getName() );
91 return GraphicsView_Object::highlight( theX, theY );
94 //=================================================================================
95 // function : unhighlight()
96 // purpose : set properties for unhighlighted item
97 //=================================================================================
98 void DependencyTree_Object::unhighlight()
101 myPolygonItem->setBrush( mySelectColor );
102 else if( myIsMainObject )
103 myPolygonItem->setBrush( myMainObjectColor );
105 myPolygonItem->setBrush( myColor );
107 myPolygonItem->setPen( getPen( myPolygonItem->brush().color() ) );
109 GraphicsView_Object::unhighlight();
112 //=================================================================================
113 // function : select()
114 // purpose : select current item
115 //=================================================================================
116 bool DependencyTree_Object::select( double theX, double theY, const QRectF& theRect )
118 myPolygonItem->setBrush( mySelectColor );
119 myPolygonItem->setPen( getPen( mySelectColor ) );
121 return GraphicsView_Object::select( theX, theY, theRect );
124 //=================================================================================
125 // function : unselect()
126 // purpose : set properties for unselected item
127 //=================================================================================
128 void DependencyTree_Object::unselect()
131 myPolygonItem->setBrush( myMainObjectColor );
133 myPolygonItem->setBrush( myColor );
135 myPolygonItem->setPen( getPen( myPolygonItem->brush().color() ) );
137 GraphicsView_Object::unselect();
140 //=================================================================================
141 // function : getEntry()
142 // purpose : get entry of current item
143 //=================================================================================
144 std::string DependencyTree_Object::getEntry() const
149 //=================================================================================
150 // function : updateName()
151 // purpose : update name of current item using its entry
152 //=================================================================================
153 void DependencyTree_Object::updateName()
155 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
156 SalomeApp_Application* app = dynamic_cast< SalomeApp_Application* >( SUIT_Session::session()->activeApplication() );
158 SalomeApp_Study* study = dynamic_cast<SalomeApp_Study*>(app->activeStudy());
159 SALOMEDS::Study_var aStudyDS = GeometryGUI::ClientStudyToStudy( study->studyDS());
160 int StudyId = aStudyDS->StudyId();
161 GEOM::_objref_GEOM_BaseObject* object = GeometryGUI::GetGeomGen()->GetObject( StudyId, myEntry.c_str() );
163 QString name = object->GetName();
164 QString StudyEntry = object->GetStudyEntry();
165 std::cout << "\n\n\n StudyEntry = " << StudyEntry.toStdString() << " " << StudyEntry.isEmpty() << std::endl;
168 if( StudyEntry.isEmpty() ) {
170 name = "unpublished";
171 myColor = resMgr->colorValue( "Geometry", "dependency_tree_background_color", QColor( 255, 255, 255 ) );
176 myTextItem->setText( name );
177 double textWidth = myTextItem->sceneBoundingRect().width();
178 double textHeight = myTextItem->sceneBoundingRect().height();
180 double polygonWidth = myPolygonItem->sceneBoundingRect().width();
181 double polygonHeight = myPolygonItem->sceneBoundingRect().height();
183 if( ( textWidth - 4 ) > polygonWidth ) {
185 int numberSymbol = int( polygonWidth * name.length() / textWidth );
186 QString newName = name.left( numberSymbol - 3 ) + "...";
187 myTextItem->setText( newName );
188 textWidth = myTextItem->sceneBoundingRect().width();
190 myTextItem->setPos( ( polygonWidth - textWidth ) / 2 - itemW,
191 ( polygonHeight - textHeight ) / 2 - itemH );
194 //=================================================================================
195 // function : setColor()
196 // purpose : set default color of current item
197 //=================================================================================
198 void DependencyTree_Object::setColor( const QColor& theColor )
203 //=================================================================================
204 // function : setSelectColor()
205 // purpose : set color of selected item
206 //=================================================================================
207 void DependencyTree_Object::setSelectColor( const QColor& theColor )
209 mySelectColor = theColor;
212 //=================================================================================
213 // function : setMainObjectColor()
214 // purpose : set color if current item is main object of dependency tree
215 //=================================================================================
216 void DependencyTree_Object::setMainObjectColor( const QColor& theColor )
218 myMainObjectColor = theColor;
221 //=================================================================================
222 // function : setIsMainObject()
223 // purpose : set true if current item is main object of dependency tree
224 //=================================================================================
225 void DependencyTree_Object::setIsMainObject( bool theIsMainObject )
227 myIsMainObject = theIsMainObject;
230 myPolygonItem->setBrush( myMainObjectColor );
232 myPolygonItem->setBrush( myColor );
234 myPolygonItem->setPen( getPen( myPolygonItem->brush().color() ) );
237 //=================================================================================
238 // function : getPen()
239 // purpose : get pen which is dependent of current color
240 //=================================================================================
241 QPen DependencyTree_Object::getPen( const QColor& theColor )
243 int value = ( theColor.value() - 100 ) > 10 ? theColor.value() - 100 : 10;
245 penColor.setHsv( theColor.hsvHue(), theColor.saturation(), value );
246 return QPen( QBrush( penColor ), 4 );