7fd59977 |
1 | #include <qlayout.h> |
2 | #include <qpushbutton.h> |
3 | #include <qframe.h> |
4 | #include <qcheckbox.h> |
5 | #include <qlabel.h> |
6 | #include <qcombobox.h> |
7 | #include <qspinbox.h> |
8 | |
9 | #include <Aspect_TypeOfLine.hxx> |
10 | #include <Graphic3d_AspectFillArea3d.hxx> |
11 | #include <Graphic3d_AspectLine3d.hxx> |
12 | #include <V3d_TypeOfVisualization.hxx> |
13 | #include <Prs3d_LineAspect.hxx> |
14 | #include <Prs3d_ShadingAspect.hxx> |
15 | #include <AIS_InteractiveObject.hxx> |
16 | #include <AIS_Drawer.hxx> |
17 | |
18 | #include "ObjectDlg.h" |
19 | #include "global.h" |
20 | |
21 | ////////////////////////////////////////////////////////////////////// |
22 | // Construction/Destruction |
23 | ////////////////////////////////////////////////////////////////////// |
24 | |
25 | ObjectDlg::ObjectDlg( QWidget* parent, Handle(V3d_View)& view, |
26 | Handle(AIS_InteractiveContext)& cxt ) |
27 | : QDialog( parent ), |
28 | myAutoApply( true ), myView( view ), myContext( cxt ) |
c6c9371f |
29 | { |
7fd59977 |
30 | setModal( false ); |
31 | setWindowTitle( tr( "TITLE_OBJECT_DLG" ) ); |
32 | |
33 | QVBoxLayout* topLayout = new QVBoxLayout( this ); |
34 | topLayout->setMargin( 5 ); |
35 | |
36 | QFrame* mainFrame = new QFrame( this ); |
37 | mainFrame->setFrameStyle( QFrame::Box | QFrame::Sunken ); |
38 | topLayout->addWidget( mainFrame ); |
39 | topLayout->addSpacing( 10 ); |
40 | |
41 | // view properties |
c6c9371f |
42 | QGridLayout* pLayout = new QGridLayout( mainFrame ); |
7fd59977 |
43 | pLayout->setMargin( 5 ); |
44 | myDegModelLabel = new QLabel( tr("MEN_DLG_DEGMODEL"), mainFrame ); |
45 | myDegRatioLabel = new QLabel( tr("MEN_DLG_DEGRATIO"), mainFrame ); |
46 | |
47 | myDegModelBox = new QComboBox( mainFrame ); |
48 | myDegModelBox->addItem( tr( "MEN_DLG_NODEGENERATION" ) ); |
49 | myDegModelBox->addItem( tr( "MEN_DLG_TINYDEGENERATION" ) ); |
50 | myDegModelBox->addItem( tr( "MEN_DLG_WIREDEGENERATION" ) ); |
51 | myDegModelBox->addItem( tr( "MEN_DLG_MARKERDEGENERATION" ) ); |
52 | myDegModelBox->addItem( tr( "MEN_DLG_BBOXDEGENERATION" ) ); |
53 | myCurrentDegModel = NoDegId; |
54 | myCurrentDegRatio = 0.; |
55 | verify( connect( myDegModelBox, SIGNAL( activated( int ) ), SLOT( onDegenerateModel( int ) ) ) ); |
56 | |
57 | //QSpinBox* degRatioSpin = new QSpinBox( mainFrame ); |
58 | //QSpinBox ( QWidget * parent = 0, const char * name = 0 ) |
c6c9371f |
59 | myDegRatioSpin = new QSpinBox( mainFrame ); |
60 | myDegRatioSpin->setRange(0, 10); |
7fd59977 |
61 | myDegRatioSpin->setSingleStep(1); |
62 | verify( connect( myDegRatioSpin, SIGNAL( valueChanged( int ) ), SLOT( onDegRatio( int ) ) ) ); |
63 | |
64 | QCheckBox* showEdges = new QCheckBox( mainFrame ); |
65 | showEdges->setText( tr( "BTN_SHOWEDGES" ) ); |
66 | verify( connect( showEdges, SIGNAL( toggled( bool ) ), SLOT( onShowEdges( bool ) ) ) ); |
67 | |
68 | myEdgeStyle = new QLabel( tr("MEN_DLG_EDGESTYLE"), mainFrame ); |
69 | myEdgeWidth = new QLabel( tr("MEN_DLG_EDGEWIDTH"), mainFrame ); |
70 | |
71 | myEdgeBox = new QComboBox( mainFrame ); |
72 | myEdgeBox->addItem( tr( "MEN_DLG_EDGESOLID" ) ); |
73 | myEdgeBox->addItem( tr( "MEN_DLG_EDGEDASH" ) ); |
74 | myEdgeBox->addItem( tr( "MEN_DLG_EDGEDOT" ) ); |
75 | myEdgeBox->addItem( tr( "MEN_DLG_EDGEDOTDASH" ) ); |
76 | myCurrentEdgeStyle = SolidEdgeId; |
77 | verify( connect( myEdgeBox, SIGNAL( activated( int ) ), SLOT( onEdgeStyle( int ) ) ) ); |
78 | |
79 | //myEdgeSpin = new QSpinBox( mainFrame ); |
c6c9371f |
80 | myEdgeSpin = new QSpinBox( mainFrame ); |
81 | myEdgeSpin->setRange(1, 10); |
7fd59977 |
82 | myEdgeSpin->setSingleStep(10); |
83 | verify( connect( myEdgeSpin, SIGNAL( valueChanged( int ) ), SLOT( onEdgeWidth( int ) ) ) ); |
84 | |
85 | onShowEdges( false ); |
86 | |
87 | pLayout->addWidget( myDegModelLabel, 0, 0 ); |
88 | pLayout->addWidget( myDegRatioLabel, 1, 0 ); |
89 | pLayout->addWidget( myDegModelBox, 0, 2 ); |
90 | pLayout->addWidget( myDegRatioSpin, 1, 2 ); |
91 | pLayout->addWidget( showEdges, 2, 0 ); |
92 | pLayout->addWidget( myEdgeStyle, 3, 0 ); |
93 | pLayout->addWidget( myEdgeWidth, 4, 0 ); |
94 | pLayout->addWidget( myEdgeBox, 3, 2 ); |
95 | pLayout->addWidget( myEdgeSpin, 4, 2 ); |
96 | pLayout->setRowStretch( 5, 10 ); |
97 | pLayout->setColumnStretch( 1, 10 ); |
98 | |
99 | // apply controls |
100 | QCheckBox *autoApply; |
101 | autoApply = new QCheckBox( this ); |
102 | autoApply->setText( tr( "BTN_AUTOAPPLY" ) ); |
103 | autoApply->setChecked( true ); |
104 | verify( connect( autoApply, SIGNAL( toggled( bool ) ), SLOT( onAutoApply( bool ) ) ) ); |
105 | |
106 | QHBoxLayout* applyLayout = new QHBoxLayout(); |
107 | applyLayout->addWidget( autoApply ); |
c6c9371f |
108 | applyLayout->addStretch( 10 ); |
7fd59977 |
109 | topLayout->addLayout(applyLayout); |
110 | topLayout->addSpacing( 10 ); |
111 | |
112 | // control buttons |
113 | QPushButton *bOk, *bCancel/*, *bHelp*/; |
114 | bOk = new QPushButton( tr( "BTN_OK" ), this ); |
115 | verify( connect( bOk, SIGNAL( clicked() ), SLOT( onOk() ) ) ); |
116 | bCancel = new QPushButton( tr( "BTN_CANCEL" ), this ); |
117 | verify( connect( bCancel, SIGNAL( clicked() ), SLOT( onCancel() ) ) ); |
c6c9371f |
118 | // bHelp = new QPushButton( tr( "BTN_HELP" ), this ); |
119 | // verify( connect( bHelp, SIGNAL( clicked() ), SLOT( onHelp() ) ) ); |
7fd59977 |
120 | |
121 | QHBoxLayout* btnLayout = new QHBoxLayout(); |
122 | btnLayout->setSpacing( 5 ); |
c6c9371f |
123 | btnLayout->addStretch( 10 ); |
7fd59977 |
124 | btnLayout->addWidget( bOk ); |
125 | btnLayout->addWidget( bCancel ); |
126 | btnLayout->addStretch( 10 ); |
127 | // btnLayout->addWidget( bHelp ); |
c6c9371f |
128 | topLayout->addLayout(btnLayout); |
7fd59977 |
129 | |
130 | QSize s = topLayout->totalMinimumSize(); |
131 | s.setWidth( s.width() + topLayout->margin() + 10 ); |
132 | s.setHeight( s.height() + topLayout->margin() + 10 ); |
133 | setFixedSize( s ); |
134 | } |
135 | |
136 | ObjectDlg::~ObjectDlg() |
137 | { |
138 | } |
139 | |
140 | void ObjectDlg::showEvent ( QShowEvent* e ) |
141 | { |
142 | QWidget::showEvent( e ); |
143 | |
144 | Standard_Boolean isDeg, isAnim, isEnabled; |
145 | isAnim = myView->AnimationMode( isDeg ); |
146 | isEnabled = isDeg && isAnim; |
147 | myDegModelLabel->setEnabled( isEnabled ); |
148 | myDegRatioLabel->setEnabled( isEnabled ); |
149 | myDegModelBox->setEnabled( isEnabled ); |
150 | myDegRatioSpin->setEnabled( isEnabled ); |
151 | } |
152 | |
153 | void ObjectDlg::onOk() |
154 | { |
155 | hide(); |
156 | } |
157 | |
158 | void ObjectDlg::onCancel() |
159 | { |
160 | hide(); |
161 | } |
162 | |
163 | void ObjectDlg::onHelp() |
164 | { |
165 | } |
166 | |
167 | void ObjectDlg::onShowEdges( bool on ) |
168 | { |
169 | if ( myAutoApply ) { |
170 | myEdgeStyle->setEnabled( on ); |
171 | myEdgeWidth->setEnabled( on ); |
172 | myEdgeBox->setEnabled( on ); |
173 | myEdgeSpin->setEnabled( on ); |
174 | |
175 | Handle(AIS_InteractiveObject) object; |
176 | Handle(Prs3d_ShadingAspect) aspect; |
177 | myContext->InitSelected(); |
178 | for( ; myContext->MoreSelected(); myContext->NextSelected() ) { |
179 | object = myContext->SelectedInteractive(); |
180 | aspect = object->Attributes()->ShadingAspect(); |
181 | if ( on ) |
182 | aspect->Aspect()->SetEdgeOn(); |
183 | else |
184 | aspect->Aspect()->SetEdgeOff(); |
185 | object->SetAspect( aspect ); |
186 | } |
187 | //myContext->UpdateCurrentViewer(); |
188 | myView->Update(); |
189 | } |
190 | } |
191 | |
192 | void ObjectDlg::onDegenerateModel( int index ) |
193 | { |
194 | if ( myCurrentDegModel != index ) { |
195 | |
196 | switch ( index ) { |
197 | case NoDegId : |
198 | myDegModel = Aspect_TDM_NONE; |
199 | break; |
200 | case TinyDegId : |
201 | myDegModel = Aspect_TDM_TINY; |
202 | break; |
203 | case WireDegId : |
204 | myDegModel = Aspect_TDM_WIREFRAME; |
205 | break; |
206 | case MarkerDegId : |
207 | myDegModel = Aspect_TDM_MARKER; |
208 | break; |
209 | case BBoxDegId : |
210 | myDegModel = Aspect_TDM_BBOX; |
211 | break; |
212 | } |
213 | myCurrentDegModel = index; |
214 | updateDegenerationModel(); |
215 | } |
216 | } |
217 | |
218 | void ObjectDlg::onDegRatio( int ratio ) |
219 | { |
220 | myCurrentDegRatio = ratio / 10.; |
221 | updateDegenerationModel(); |
222 | } |
223 | |
224 | void ObjectDlg::onEdgeStyle( int index ) |
225 | { |
226 | if ( myCurrentEdgeStyle != index ) { |
227 | myCurrentEdgeStyle = index; |
228 | updateEdgeAspect( true ); |
229 | } |
230 | } |
231 | |
232 | void ObjectDlg::onEdgeWidth( int value ) |
233 | { |
234 | myCurrentEdgeWidth = (float) value; |
235 | updateEdgeAspect( false ); |
236 | } |
237 | |
238 | void ObjectDlg::onAutoApply( bool on ) |
239 | { |
240 | myAutoApply = on; |
241 | } |
242 | |
243 | void ObjectDlg::updateEdgeAspect( bool edgeStyle ) |
c6c9371f |
244 | { |
245 | Aspect_TypeOfLine type; |
246 | if ( edgeStyle ) |
247 | switch( myCurrentEdgeStyle ) { |
248 | case SolidEdgeId : |
249 | type = Aspect_TOL_SOLID; |
250 | break; |
251 | case DashEdgeId : |
252 | type = Aspect_TOL_DASH; |
253 | break; |
254 | case DotEdgeId : |
255 | type = Aspect_TOL_DOT; |
256 | break; |
257 | case DotDashEdgeId : |
258 | type = Aspect_TOL_DOTDASH; |
259 | break; |
260 | } |
261 | Handle(AIS_InteractiveObject) object; |
262 | Handle(Prs3d_ShadingAspect) aspect; |
263 | myContext->InitSelected(); |
264 | for( ; myContext->MoreSelected(); myContext->NextSelected() ) { |
265 | object = myContext->SelectedInteractive(); |
266 | aspect = object->Attributes()->ShadingAspect(); |
267 | if ( edgeStyle ) |
268 | aspect->Aspect()->SetEdgeLineType( type ); |
269 | else |
270 | aspect->Aspect()->SetEdgeWidth( myCurrentEdgeWidth ); |
271 | object->SetAspect( aspect ); |
272 | } |
273 | if ( myAutoApply ) |
274 | //myContext->UpdateCurrentViewer(); |
275 | myView->Viewer()->Update(); |
7fd59977 |
276 | } |
277 | |
278 | void ObjectDlg::updateDegenerationModel() |
279 | { |
280 | //myView->SetAnimationModeOff(); |
281 | Handle(AIS_InteractiveObject) object; |
282 | for( myContext->InitSelected(); myContext->MoreSelected(); myContext->NextSelected() ) { |
283 | object = myContext->SelectedInteractive(); |
284 | object->SetDegenerateModel( myDegModel, myCurrentDegRatio ); |
285 | } |
286 | //myView->SetAnimationModeOn(); |
287 | |
288 | if ( myAutoApply ) |
289 | //myView->Update(); |
290 | myContext->UpdateCurrentViewer(); |
291 | } |