-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathSketcher_Property.cxx
592 lines (535 loc) · 16.7 KB
/
Sketcher_Property.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
/**
* \file Sketcher_Property.cxx
* \brief Implementation file for the class Sketcher_Property
* \author <a href="mailto:[email protected]?subject=Sketcher_Property.cxx">Sergei Maslov</a>
*/
#include "Sketcher_Property.hxx"
#include <qcombobox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlineedit.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qpixmap.h>
/**
* \fn Sketcher_Property( QWidget* parent, const char* name, WFlags fl )
* \brief Constructs a Sketcher_Property which is a child of 'parent', with the name 'name' and widget flags set to 'f'
* \param parent QWidget*
* \param name const char*
* \param fl WFlags
*/
Sketcher_Property::Sketcher_Property( QWidget* parent, const char* name)
: QWidget( parent),
StartCoord("["),MidCoord(","),EndCoord("]"),
NumberExpr("[^0-9.-]")
{
if ( !name )
setWindowTitle( "Sketcher_Property" );
resize( 288, 369 );
setMaximumSize( QSize( 400, 400 ) );
//setCaption( tr( "Properties" ) );
////////////////////////////////////////////////////////////////////////////////
TextLabelID = new QLabel( "TextLabelID", this );
TextLabelID->setText( tr( "ID" ) );
LineEditID = new QLineEdit( "LineEditID", this );
////////////////////////////////////////////////////////////////////////////////
GroupBoxGP = new QGroupBox( "GroupBoxGP", this );
GroupBoxGP->setTitle( tr( "Geometry Properties" ) );
//GroupBoxGP->setColumnLayout(0, Qt::Vertical );
GroupBoxGP->layout()->setSpacing( 0 );
GroupBoxGP->layout()->setMargin( 0 );
TextLabelPoint1 = new QLabel("TextLabelPoint1", GroupBoxGP);
LineEditPoint1 = new QLineEdit( "LineEditPoint1", GroupBoxGP);
GroupBoxGPLayout = new QGridLayout( GroupBoxGP);
GroupBoxGPLayout->setAlignment( Qt::AlignTop );
GroupBoxGPLayout->setSpacing( 6 );
GroupBoxGPLayout->setMargin( 11 );
GroupBoxGPLayout->addWidget( TextLabelPoint1, 0, 0 );
GroupBoxGPLayout->addWidget( LineEditPoint1, 0, 1 );
///////////////////////////////////////////////////////////////////////////////
GroupBoxAttributes = new QGroupBox( "GroupBoxAttributes", this );
GroupBoxAttributes->setTitle( tr( "Attributes" ) );
//GroupBoxAttributes->setColumnLayout(0, Qt::Vertical );
GroupBoxAttributes->layout()->setSpacing( 0 );
GroupBoxAttributes->layout()->setMargin( 0 );
TextLabelColor = new QLabel( GroupBoxAttributes);
TextLabelColor->setText( tr( "Color" ) );
ComboBoxColor = new QComboBox( GroupBoxAttributes);
ComboBoxColor->addItem( tr( "BLACK" ) );
ComboBoxColor->addItem( tr( "BROWN" ) );
ComboBoxColor->addItem( tr( "RED" ) );
ComboBoxColor->addItem( tr( "ORANGE" ) );
ComboBoxColor->addItem( tr( "YELLOW" ) );
ComboBoxColor->addItem( tr( "FORESTGREEN" ) );
ComboBoxColor->addItem( tr( "GREEN" ) );
ComboBoxColor->addItem( tr( "BLUE" ) );
ComboBoxColor->addItem( tr( "DEEPSKYBLUE1" ) );
ComboBoxColor->addItem( tr( "LIGHTSKYBLUE" ) );
ComboBoxColor->addItem( tr( "CYAN" ) );
ComboBoxColor->addItem( tr( "PURPLE" ) );
ComboBoxColor->addItem( tr( "MAGENTA" ) );
ComboBoxColor->addItem( tr( "VIOLET" ) );
ComboBoxColor->addItem( tr( "DEEPPINK" ) );
ComboBoxColor->addItem( tr( "PINK" ) );
ComboBoxColor->addItem( tr( "GRAY" ) );
ComboBoxColor->addItem( tr( "WHITE" ) );
TextLabelType = new QLabel( "TextLabelType", GroupBoxAttributes);
TextLabelType->setText( tr( "Type" ) );
ComboBoxType = new QComboBox( GroupBoxAttributes);
ComboBoxType->addItem( tr( "Main" ) );
ComboBoxType->addItem( tr( "Auxiliary" ) );
GroupBoxAttributesLayout = new QGridLayout( GroupBoxAttributes);
GroupBoxAttributesLayout->setAlignment( Qt::AlignTop );
GroupBoxAttributesLayout->setSpacing( 6 );
GroupBoxAttributesLayout->setMargin( 11 );
GroupBoxAttributesLayout->addWidget( TextLabelColor, 0, 0 );
GroupBoxAttributesLayout->addWidget( ComboBoxColor, 0, 1 );
GroupBoxAttributesLayout->addWidget( TextLabelType, 1, 0 );
GroupBoxAttributesLayout->addWidget( ComboBoxType, 1, 1 );
////////////////////////////////////////////////////////////////////////////////////
PushButtonOK = new QPushButton( "PushButtonOK", this );
PushButtonOK->setMinimumSize ( 70, 25 );
PushButtonOK->setText( tr( "OK" ) );
PushButtonCancel = new QPushButton( "PushButtonCancel", this );
PushButtonCancel->setMinimumSize ( 70, 25 );
PushButtonCancel->setText( tr( "Cancel" ) );
PushButtonApply = new QPushButton( "PushButtonApply", this );
PushButtonApply->setMinimumSize ( 70, 25 );
PushButtonApply->setText( tr( "Apply" ) );
QSpacerItem* spacer_1 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
QSpacerItem* spacer_3 = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding );
QSpacerItem* spacerOK_Cancel = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
QSpacerItem* spacerCancel_Apply = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
PropertyLayout = new QGridLayout( this );
PropertyLayout->setSpacing( 6 );
PropertyLayout->setMargin( 11 );
PropertyLayout->addWidget( TextLabelID, 0, 0 );
//PropertyLayout->addMultiCellWidget( LineEditID, 0, 0, 1, 5 );
PropertyLayout->addItem( spacer_1, 1, 3 );
//PropertyLayout->addMultiCellWidget( GroupBoxGP, 2, 2, 0, 5 );
PropertyLayout->addItem( spacer_2, 3, 3 );
//PropertyLayout->addMultiCellWidget( GroupBoxAttributes, 4, 4, 0, 5 );
PropertyLayout->addItem( spacer_3, 5, 3 );
//PropertyLayout->addMultiCellWidget( PushButtonOK, 6, 6, 0, 1 );
PropertyLayout->addItem( spacerOK_Cancel, 6, 2 );
PropertyLayout->addWidget( PushButtonCancel, 6, 3 );
PropertyLayout->addItem( spacerCancel_Apply, 6, 4 );
PropertyLayout->addWidget( PushButtonApply, 6, 5 );
connect( PushButtonOK, SIGNAL( clicked() ), this, SLOT( onOK( ) ) );
connect( PushButtonCancel, SIGNAL( clicked() ), this, SLOT( close() ) );
connect( PushButtonApply, SIGNAL( clicked() ), this, SLOT( onApply () ) );
QString fileName( tr("res"));
fileName=fileName + QString("/") + QString( tr("property.png"));
QPixmap myIcon( fileName);//, const char * format, int conversion_flags )
setWindowIcon (myIcon);
myNameOfColor = Quantity_NOC_YELLOW;
myObjectStyle = Aspect_TOL_SOLID;
myWidth = 1.0;
myPrs3dAspect = new Prs3d_LineAspect(myNameOfColor,myObjectStyle,myWidth);
myDrawer = new Prs3d_Drawer();
myDrawer->SetLineAspect(myPrs3dAspect);
}
/**
* \fn ~Sketcher_Property()
* \brief destructor
*/
Sketcher_Property::~Sketcher_Property()
{
// no need to delete child widgets, Qt does it all for us
}
/**
* \fn Init()
* \brief Constructs a supplementary elements
* \return void
*/
void Sketcher_Property::Init()
{
isPointWindow = false;
TextLabelStyle = new QLabel( "TextLabelStyle", GroupBoxAttributes);
TextLabelStyle->setText( tr( "Style" ) );
ComboBoxStyle = new QComboBox(GroupBoxAttributes);
ComboBoxStyle->addItem( tr( "SOLID" ) );
ComboBoxStyle->addItem( tr( "DASH" ) );
ComboBoxStyle->addItem( tr( "DOT" ) );
ComboBoxStyle->addItem( tr( "DOTDASH" ) );
TextLabelWidth = new QLabel("TextLabelWidth", GroupBoxAttributes);
TextLabelWidth->setText( tr( "Width" ) );
ComboBoxWidth = new QComboBox(GroupBoxAttributes);
ComboBoxWidth->addItem( tr( "1.0" ) );
ComboBoxWidth->addItem( tr( "2.0" ) );
ComboBoxWidth->addItem( tr( "3.0" ) );
ComboBoxWidth->addItem( tr( "4.0" ) );
ComboBoxWidth->addItem( tr( "5.0" ) );
ComboBoxWidth->addItem( tr( "6.0" ) );
ComboBoxWidth->addItem( tr( "7.0" ) );
ComboBoxWidth->addItem( tr( "8.0" ) );
ComboBoxWidth->addItem( tr( "9.0" ) );
GroupBoxAttributesLayout->addWidget( TextLabelStyle, 2, 0 );
GroupBoxAttributesLayout->addWidget( ComboBoxStyle, 2, 1 );
GroupBoxAttributesLayout->addWidget( TextLabelWidth, 3, 0 );
GroupBoxAttributesLayout->addWidget( ComboBoxWidth, 3, 1 );
}
/**
* \fn SetContext(Handle(AIS_InteractiveContext)& theContext)
* \brief set context
* \return void
* \param theContext Handle(AIS_InteractiveContext)&
*/
void Sketcher_Property::SetContext (Handle(AIS_InteractiveContext)& theContext)
{
myContext = theContext;
}
/**
* \fn SetAx3(const gp_Ax3& theAx3)
* \brief set coordinate system
* \return void
* \param theAx3 const gp_Ax3&
*/
void Sketcher_Property::SetAx3 (const gp_Ax3& theAx3)
{
myCoordinateSystem = theAx3;
}
/**
* \fn SetObject(Handle(Sketcher_Object)& CurObject)
* \brief set Sketcher_Object, show dialog window
* \return void
* \param CurObject Handle(Sketcher_Object)&
*/
void Sketcher_Property::SetObject(Handle(Sketcher_Object)& CurObject)
{
mySObject = CurObject;
myAIS_Object = mySObject->GetAIS_Object();
myID = mySObject->GetObjectName();
myNameOfColor = mySObject->GetColor();
myObjectType = mySObject->GetType();
if (!isPointWindow)
{
myObjectStyle = mySObject->GetStyle();
myWidth = mySObject->GetWidth();
SetObjectStyle();
SetWidth();
}
SetID();
SetColor();
SetObjectType();
SetGeometry();
show();
}
/**
* \fn onOK()
* \brief clicking on "OK" button handler
* \return void
*/
void Sketcher_Property::onOK()
{
if(CheckGeometry())
{
if (GetGeometry())
GetAttributies();
else CheckAttributies();
GetName();
mySObject->SetAIS_Object(myAIS_Object);
myContext->Display(myAIS_Object, true);
close();
}
}
/**
* \fn onApply()
* \brief clicking on "Apply" button handler
* \return void
*/
void Sketcher_Property::onApply()
{
if(CheckGeometry())
{
if (GetGeometry())
{
GetAttributies();
mySObject->SetAIS_Object(myAIS_Object);
myContext->Display(myAIS_Object, true);
}
else CheckAttributies();
GetName();
}
}
/**
* \fn SetID()
* \brief set object name to LineEditID
* \return void
*/
void Sketcher_Property::SetID ()
{
LineEditID->setText(QString((QChar*)myID.ToExtString(), myID.Length ()));
}
/**
* \fn GetID()
* \brief get text from LineEditID
* \return TCollection_ExtendedString
*/
TCollection_ExtendedString Sketcher_Property::GetID ()
{
return TCollection_ExtendedString((char *)LineEditID->text().toLocal8Bit ().data() );
}
/**
* \fn SetCoord(QLineEdit* le,const gp_Pnt2d& p)
* \brief set point coordinate to le
* \return void
* \param le QLineEdit*
* \param p const gp_Pnt2d&
*/
void Sketcher_Property::SetCoord(QLineEdit* le,const gp_Pnt2d& p)
{
NumName = StartCoord;
NumName+= QString::number(p.X());
NumName+= MidCoord;
NumName+= QString::number(p.Y());
NumName+= EndCoord;
le->setText(NumName);
}
/**
* \fn CheckCoord(QLineEdit* le,const gp_Pnt2d& p)
* \brief get point coordinate from le
* \return bool
* \param le QLineEdit*
* \param p const gp_Pnt2d&
*/
bool Sketcher_Property::CheckCoord(QLineEdit* le, gp_Pnt2d& p)
{
int pos = 0;
QString Xstring,Ystring;
NumName = le->text();
if(NumName.left(1) == StartCoord && NumName.right(1) == EndCoord)
{
NumName = NumName.mid(1,NumName.length()-2);
pos = NumName.indexOf ( MidCoord );
if (pos > 0)
{
Xstring = NumName.left(pos);
if(Xstring.contains(NumberExpr) == 0 && !Xstring.isNull())
{
Ystring = NumName.right(NumName.length()-pos-1);
if(Ystring.contains(NumberExpr) == 0 && !Ystring.isNull())
{
p.SetCoord(Xstring.toDouble(),Ystring.toDouble());
return true;
}
}
}
}
le->selectAll();
return false;
}
/**
* \fn CheckAttributies()
* \brief check attributes for change
* \return void
*/
void Sketcher_Property::CheckAttributies()
{
if (myNameOfColor != GetColor() || myObjectStyle != GetObjectStyle() || myWidth != GetWidth())
{
GetAttributies();
myContext->Redisplay(myAIS_Object, true);
}
}
/**
* \fn GetAttributies()
* \brief set attributes to object
* \return void
*/
void Sketcher_Property::GetAttributies()
{
myNameOfColor = GetColor();
mySObject->SetColor(myNameOfColor);
if (isPointWindow) myAIS_Object->SetColor(myNameOfColor);
else
{
myObjectStyle = GetObjectStyle();
myWidth = GetWidth();
mySObject->SetStyle(myObjectStyle);
mySObject->SetWidth(myWidth);
myPrs3dAspect->SetColor(myNameOfColor);
myPrs3dAspect->SetTypeOfLine(myObjectStyle);
myPrs3dAspect->SetWidth(myWidth);
myDrawer->SetLineAspect(myPrs3dAspect);
myAIS_Object->SetAttributes(myDrawer);
}
}
/**
* \fn GetName()
* \brief check name and type of object for change
* \return void
*/
void Sketcher_Property::GetName()
{
tempID = GetID();
if (!myID.IsEqual(tempID))
{
myID = tempID;
mySObject->SetObjectName(myID);
}
if (myObjectType != GetObjectType())
{
myObjectType = GetObjectType();
mySObject->SetType(myObjectType);
}
}
/**
* \fn SetColor()
* \brief show object color in dialog window
* \return void
*/
void Sketcher_Property::SetColor()
{
switch(myNameOfColor)
{
case Quantity_NOC_BLACK: ComboBoxColor->setCurrentIndex ( 0 );
break;
case Quantity_NOC_BROWN: ComboBoxColor->setCurrentIndex ( 1 );
break;
case Quantity_NOC_RED: ComboBoxColor->setCurrentIndex ( 2 );
break;
case Quantity_NOC_ORANGE: ComboBoxColor->setCurrentIndex ( 3 );
break;
case Quantity_NOC_YELLOW: ComboBoxColor->setCurrentIndex ( 4 );
break;
case Quantity_NOC_FORESTGREEN: ComboBoxColor->setCurrentIndex ( 5 );
break;
case Quantity_NOC_GREEN: ComboBoxColor->setCurrentIndex ( 6 );
break;
case Quantity_NOC_BLUE1: ComboBoxColor->setCurrentIndex ( 7 );
break;
case Quantity_NOC_DEEPSKYBLUE1: ComboBoxColor->setCurrentIndex ( 8 );
break;
case Quantity_NOC_LIGHTSKYBLUE: ComboBoxColor->setCurrentIndex ( 9 );
break;
case Quantity_NOC_CYAN1: ComboBoxColor->setCurrentIndex ( 10 );
break;
case Quantity_NOC_PURPLE: ComboBoxColor->setCurrentIndex ( 11 );
break;
case Quantity_NOC_MAGENTA1: ComboBoxColor->setCurrentIndex ( 12 );
break;
case Quantity_NOC_VIOLET: ComboBoxColor->setCurrentIndex ( 13 );
break;
case Quantity_NOC_DEEPPINK: ComboBoxColor->setCurrentIndex ( 14 );
break;
case Quantity_NOC_PINK: ComboBoxColor->setCurrentIndex ( 15 );
break;
case Quantity_NOC_GRAY70: ComboBoxColor->setCurrentIndex ( 16 );
break;
case Quantity_NOC_WHITE: ComboBoxColor->setCurrentIndex ( 17 );
break;
default: ComboBoxColor->setCurrentIndex ( 4 );
break;
}
}
/**
* \fn GetColor()
* \brief get object color from dialog window
* \return Quantity_NameOfColor
*/
Quantity_NameOfColor Sketcher_Property::GetColor()
{
switch(ComboBoxColor->currentIndex ())
{
case 0: return Quantity_NOC_BLACK;
break;
case 1: return Quantity_NOC_BROWN;
break;
case 2: return Quantity_NOC_RED;
break;
case 3: return Quantity_NOC_ORANGE;
break;
case 4: return Quantity_NOC_YELLOW;
break;
case 5: return Quantity_NOC_FORESTGREEN;
break;
case 6: return Quantity_NOC_GREEN;
break;
case 7: return Quantity_NOC_BLUE1;
break;
case 8: return Quantity_NOC_DEEPSKYBLUE1;
break;
case 9: return Quantity_NOC_LIGHTSKYBLUE;
break;
case 10: return Quantity_NOC_CYAN1;
break;
case 11: return Quantity_NOC_PURPLE;
break;
case 12: return Quantity_NOC_MAGENTA1;
break;
case 13: return Quantity_NOC_VIOLET;
break;
case 14: return Quantity_NOC_DEEPPINK;
break;
case 15: return Quantity_NOC_PINK;
break;
case 16: return Quantity_NOC_GRAY70;
break;
case 17: return Quantity_NOC_WHITE;
break;
default: return Quantity_NOC_YELLOW;
break;
}
}
/**
* \fn SetObjectType()
* \brief show object type in dialog window
* \return void
*/
void Sketcher_Property::SetObjectType()
{
ComboBoxType->setCurrentIndex ((int) myObjectType );
}
/**
* \fn GetObjectType()
* \brief get object type from dialog window
* \return Sketcher_ObjectType
*/
Sketcher_ObjectType Sketcher_Property::GetObjectType()
{
return (Sketcher_ObjectType)ComboBoxType->currentIndex ();
}
/**
* \fn SetObjectStyle()
* \brief show object line style in dialog window
* \return void
*/
void Sketcher_Property::SetObjectStyle()
{
ComboBoxStyle->setCurrentIndex ((int) myObjectStyle );
}
/**
* \fn GetObjectStyle()
* \brief get object line style from dialog window
* \return Aspect_TypeOfLine
*/
Aspect_TypeOfLine Sketcher_Property::GetObjectStyle()
{
if (isPointWindow) return Aspect_TOL_SOLID;
else return (Aspect_TypeOfLine)ComboBoxStyle->currentIndex ();
}
/**
* \fn SetWidth()
* \brief show object line width in dialog window
* \return void
*/
void Sketcher_Property::SetWidth()
{
ComboBoxWidth->setCurrentIndex (((int)myWidth) -1);
}
/**
* \fn GetWidth()
* \brief get object line width from dialog window
* \return Standard_Real
*/
Standard_Real Sketcher_Property::GetWidth()
{
if (isPointWindow) return 1.0;
else
return (double)(ComboBoxWidth->currentIndex () +1);
}