-
Notifications
You must be signed in to change notification settings - Fork 0
/
dimensionview.cpp
1073 lines (878 loc) · 40.7 KB
/
dimensionview.cpp
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
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* dimensionview.cpp
*
* DimensionView classes: The View and Controllers for Dimensions
* Copyright (C) 2002 lignum Computing, Inc. <lignumcad@lignumcomputing.com>
* $Id$
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <qapplication.h>
#include <qaction.h>
#include <QMenu>
#include <qwhatsthis.h>
#include <qlineedit.h>
#include <qradiobutton.h>
#include <qbuttongroup.h>
#include <qcursor.h>
#include <qmessagebox.h>
#include <qpainter.h>
#include "configuration.h"
#include "units.h"
#include "command.h"
#include "openglview.h"
#include "lignumcadmainwindow.h"
#include "cursorfactory.h"
#include "line.h"
#include "pageview.h"
#include "model.h"
#include "figure.h"
#include "lcdefaultlengthspinbox.h"
#include "designbookview.h"
#include "dimensioninfodialog.h"
#include "dimensionview.h"
#include <QMouseEvent>
namespace Space2D {
DimensionCreateInput::DimensionCreateInput ( PageView* parent )
: parent_( parent ), n_geometries_( 0 ), xml_rep_( 0 )
{}
DimensionCreateInput::~DimensionCreateInput ( void )
{
if ( xml_rep_ != 0 ) delete xml_rep_;
}
void DimensionCreateInput::startDisplay ( QMenu* context_menu )
{
n_geometries_ = 0;
points_.clear();
lines_.clear();
xml_rep_ = new QDomDocument;
context_menu_ = context_menu;
QAction* cancel_action = parent_->lCMW()->getUi()->cancelDimensionAction;
separator_id_ = context_menu_->addSeparator();
context_menu_->addAction( cancel_action );
connect( cancel_action, SIGNAL( activated() ), SLOT( cancelOperation() ) );
parent_->view()->
setCursor( CursorFactory::instance().cursor( CursorFactory::DIMENSION ) );
}
void DimensionCreateInput::mousePrepress ( QMouseEvent* me,
const SelectedNames& selected )
{
(void)me;
(void)selected;
}
void DimensionCreateInput::mousePress ( QMouseEvent* me,
const SelectedNames& selected )
{
// This is in pick mode, so we only consider the first geometry
// selected (rather than all of them like we had...)
if ( selected.empty() )
return;
SelectedNames::const_iterator f = selected.begin();
if ( (*f).second.size() < 2 )
return;
FigureView* fv =
dynamic_cast< FigureView* >( parent_->figureSelectionNames()[ (*f).second[0] ].get());
// Let the first selected figure decide how many selections we need.
// (This is entirely for the Centerline, which wants 2 additional
// edges instead of the usual 1.)
if ( lines_.count() == 0 )
n_geometries_ = fv->dimensionPickCount();
GLuint g = (*f).second[1]; // (*(*f).second->begin()).first;
ConstrainedLine* line = dynamic_cast< ConstrainedLine* >( fv->geometry( g ) );
if ( line != 0 ) {
Point point = parent_->view()->unproject2D( me->pos() );
UnitsBasis::instance()->round( point );
QListIterator< std::shared_ptr<ConstrainedLine> > l( lines_ );
while ( l.hasNext() ) {
if ( line == l.next().get() ) {
QWhatsThis::showText(QCursor::pos(),
"<table cellpadding=10><tr>"
"<td><img source=\"not_allowed.png\"></td>"
"<td width=\"70%\">Cannot dimension to self.</td>"
"</tr></table>" );
return;
}
if ( fabs( fabs( line->e() * l.peekNext()->e() ) - 1. ) > lC::EPSILON ) {
QWhatsThis::showText(QCursor::pos(),
"<table cellpadding=10><tr>"
"<td><img source=\"not_allowed.png\"></td>"
"<td width=\"70%\">Cannot dimension non-parallel lines.</td>"
"</tr></table>" );
return;
}
if ( line->dependsOn( l.peekNext().get() ) ) {
QWhatsThis::showText(QCursor::pos(),
"<table cellpadding=10><tr>"
"<td><img source=\"not_allowed.png\"></td>"
"<td width=\"70%\">Dimension would create circular reference.</td>"
"</tr></table>" );
return;
}
l.next();
}
points_.push_back( point );
lines_.append( std::shared_ptr<ConstrainedLine>(line) );
}
if ( lines_.count() == 1 )
parent_->view()->
setCursor( CursorFactory::instance().cursor( CursorFactory::DIMENSIONPLUS ) );
}
void DimensionCreateInput::mouseDrag ( QMouseEvent* me,
const SelectedNames& selected )
{
(void)me;
(void)selected;
}
bool DimensionCreateInput::mouseRelease ( QMouseEvent* me,
const SelectedNames& selected )
{
(void)me;
(void)selected;
if ( n_geometries_ == 0 || lines_.count() < n_geometries_ )
return false;
// This should probably be passed off to the FigureView to do
// the right thing with...Indeed...
if ( lines_.count() == 2 ) {
ConstrainedLine* from = lines_[0].get();
ConstrainedLine* to = lines_[1].get();
QDomElement reconstraints = xml_rep_->createElement( lC::STR::RECONSTRAINTS );
xml_rep_->appendChild( reconstraints );
QDomElement old_constraints = xml_rep_->createElement(lC::STR::OLD_CONSTRAINTS);
reconstraints.appendChild( old_constraints );
QDomElement old_xml = xml_rep_->createElement( lC::STR::CONSTRAINED_LINE );
old_xml.setAttribute( lC::STR::URL, from->dbURL().toString() );
from->constraint()->write( old_xml );
old_constraints.appendChild( old_xml );
// Making this contraint can, in some cases, cause the target
// line's former reference to be reconstrained. This happens
// at least in Rectangle in order to keep a width- or height-like
// dimension. In undoing this operation, that cascade change
// must be done first in order to avoid a circular reference.
// How do we know it's going to happen? Catch the signal emitted
// when the target's former reference is reconstrained itself.
from_reference_ = dynamic_cast<ConstrainedLine*>( from->reference() );
if ( from_reference_ != 0 ) {
from_ref_xml_ = xml_rep_->createElement( lC::STR::CONSTRAINED_LINE );
from_ref_xml_.setAttribute( lC::STR::URL, from_reference_->dbURL().toString() );
from_reference_->constraint()->write( from_ref_xml_ );
// If from_reference_'s modifiedConstraint signal is emitted,
// then the old XML representation of its constraint is
// appended to this reconstrain command (done in the SLOT).
connect( from_reference_, SIGNAL( modifiedConstraint() ),
SLOT( cascadeConstraints() ) );
}
Offset* offset = new Offset( from->o(), to );
QDomElement new_constraints = xml_rep_->createElement( lC::STR::NEW_CONSTRAINTS );
reconstraints.appendChild( new_constraints );
QDomElement new_xml = xml_rep_->createElement( lC::STR::CONSTRAINED_LINE );
new_xml.setAttribute( lC::STR::URL, from->dbURL().toString() );
offset->write( new_xml );
new_constraints.appendChild( new_xml );
from->setConstraint( offset );
if ( from_reference_ != 0 )
disconnect( from_reference_, SIGNAL( modifiedConstraint() ),
this, SLOT( cascadeConstraints() ) );
CommandHistory::instance().
addCommand( new ReconstrainCommand( "reconstrain line",
parent_->model(),
xml_rep_ ) );
xml_rep_ = 0;
}
else if ( lines_.count() == 3 ) {
ConstrainedLine* to = lines_[0].get();
ConstrainedLine* from = lines_[1].get();
QDomElement reconstraints = xml_rep_->createElement( lC::STR::RECONSTRAINTS );
xml_rep_->appendChild( reconstraints );
QDomElement old_constraints = xml_rep_->createElement( lC::STR::OLD_CONSTRAINTS );
reconstraints.appendChild( old_constraints );
QDomElement old_xml = xml_rep_->createElement( lC::STR::CONSTRAINED_LINE );
old_xml.setAttribute( lC::STR::URL, from->dbURL().toString() );
from->constraint()->write( old_xml );
old_constraints.appendChild( old_xml );
// Making this contraint can, in some cases, cause the target
// line's former reference to be reconstrained. This happens
// at least in Rectangle in order to keep a width- or height-like
// dimension. In undoing this operation, that cascade change
// must be done first in order to avoid a circular reference.
// How do we know it's going to happen? Catch the signal emitted
// when the target's former reference is reconstrained itself.
from_reference_ = dynamic_cast<ConstrainedLine*>( from->reference() );
if ( from_reference_ != 0 ) {
from_ref_xml_ = xml_rep_->createElement( lC::STR::CONSTRAINED_LINE );
from_ref_xml_.setAttribute( lC::STR::URL, from_reference_->dbURL().toString() );
from_reference_->constraint()->write( from_ref_xml_ );
// If from_reference_'s modifiedConstraint signal is emitted,
// then the old XML representation of its constraint is
// appended to this reconstrain command (done in the SLOT).
connect( from_reference_, SIGNAL( modifiedConstraint() ),
SLOT( cascadeConstraints() ) );
}
from->setConstraint( new Offset( from->o(), to ) );
if ( from_reference_ != 0 )
disconnect( from_reference_, SIGNAL( modifiedConstraint() ),
this, SLOT( cascadeConstraints() ) );
QDomElement new_constraints = xml_rep_->createElement( lC::STR::NEW_CONSTRAINTS );
reconstraints.appendChild( new_constraints );
QDomElement new_xml = xml_rep_->createElement( lC::STR::CONSTRAINED_LINE );
new_xml.setAttribute( lC::STR::URL, from->dbURL().toString() );
from->constraint()->write( new_xml );
new_constraints.appendChild( new_xml );
to = lines_[1].get();
from = lines_[2].get();
// Note: Obviously, must append these subsequent changes in the
// REVERSE order of their creation!
QDomElement old_xml2 = xml_rep_->createElement( lC::STR::CONSTRAINED_LINE );
old_xml2.setAttribute( lC::STR::URL, from->dbURL().toString() );
from->constraint()->write( old_xml2 );
old_constraints.insertBefore( old_xml2, old_constraints.firstChild() );
// Making this contraint can, in some cases, cause the target
// line's former reference to be reconstrained. This happens
// at least in Rectangle in order to keep a width- or height-like
// dimension. In undoing this operation, that cascade change
// must be done first in order to avoid a circular reference.
// How do we know it's going to happen? Catch the signal emitted
// when the target's former reference is reconstrained itself.
from_reference_ = dynamic_cast<ConstrainedLine*>( from->reference() );
if ( from_reference_ != 0 ) {
from_ref_xml_ = xml_rep_->createElement( lC::STR::CONSTRAINED_LINE );
from_ref_xml_.setAttribute( lC::STR::URL, from_reference_->dbURL().toString() );
from_reference_->constraint()->write( from_ref_xml_ );
// If from_reference_'s modifiedConstraint signal is emitted,
// then the old XML representation of its constraint is
// appended to this reconstrain command (done in the SLOT).
connect( from_reference_, SIGNAL( modifiedConstraint() ),
SLOT( cascadeConstraints() ) );
}
from->setConstraint( new Centered( from->o(), to ) );
if ( from_reference_ != 0 )
disconnect( from_reference_, SIGNAL( modifiedConstraint() ),
this, SLOT( cascadeConstraints() ) );
QDomElement new_xml2 = xml_rep_->createElement( lC::STR::CONSTRAINED_LINE );
new_xml2.setAttribute( lC::STR::URL, from->dbURL().toString() );
from->constraint()->write( new_xml2 );
new_constraints.appendChild( new_xml2 );
CommandHistory::instance().
addCommand( new ReconstrainCommand( "reconstrain line",
parent_->model(),
xml_rep_ ) );
xml_rep_ = 0;
}
QAction* cancel_action = parent_->lCMW()->getUi()->cancelDimensionAction;
cancel_action->disconnect();
context_menu_ ->removeAction( cancel_action );
context_menu_->removeAction( separator_id_ );
parent_->view()->unsetCursor();
parent_->figureComplete();
return true;
}
void DimensionCreateInput::keyPress ( QKeyEvent* ke )
{
if ( ke->key() == Qt::Key_Escape )
cancelOperation();
else
ke->ignore();
}
void DimensionCreateInput::cancelOperation ( void )
{
// Normally, the Command would take responsibility for this
// object, but if the dimension creation is cancelled, it's never
// passed along.
delete xml_rep_;
xml_rep_ = 0;
QAction* cancel_action = parent_->lCMW()->getUi()->cancelDimensionAction;
cancel_action->disconnect();
context_menu_ ->removeAction( cancel_action );
context_menu_->removeAction( separator_id_ );
parent_->cancelOperation();
}
void DimensionCreateInput::cascadeConstraints ( void )
{
// The primary reconstraint target is buried deep in this representation.
// This change has to go before it so it can be undone properly.
xml_rep_->firstChild().firstChild().insertBefore( from_ref_xml_,
xml_rep_->firstChild().firstChild().firstChild() );
}
// Since these operations are unique to the dimension view, the
// undo/redo command is defined here rather than in command.cpp.
// We'll see if this is reasonable...
class MoveDimensionCommand : public Command {
DimensionView* dimension_view_;
DesignBookView* design_book_view_;
DBURL db_url_;
double old_extension_offset_;
double new_extension_offset_;
double old_dimension_offset_;
double new_dimension_offset_;
enum Dimension::Placement old_placement_;
enum Dimension::Placement new_placement_;
lC::AnnotationSide old_annotation_side_;
lC::AnnotationSide new_annotation_side_;
public:
MoveDimensionCommand ( const QString& name, DimensionView* dimension_view,
double old_extension_offset, double new_extension_offset,
double old_dimension_offset, double new_dimension_offset,
enum Dimension::Placement old_placement,
enum Dimension::Placement new_placement,
lC::AnnotationSide old_annotation_side,
lC::AnnotationSide new_annotation_side )
: Command( name ),
dimension_view_( dimension_view ),
design_book_view_( dimension_view_->parent()->parent()->parent() ),
db_url_( dimension_view_->dimension()->dbURL() ),
old_extension_offset_( old_extension_offset ),
new_extension_offset_( new_extension_offset ),
old_dimension_offset_( old_dimension_offset ),
new_dimension_offset_( new_dimension_offset ),
old_placement_( old_placement ), new_placement_( new_placement ),
old_annotation_side_( old_annotation_side ),
new_annotation_side_( new_annotation_side )
{}
Type type ( void ) const { return MoveDimension; }
bool merge ( Command* /*command*/ ) { return false; }
void execute ( void )
{
dimension_view_ =
dynamic_cast<DimensionView*>( design_book_view_->lookup( db_url_ ) );
dimension_view_->setDimensionAttributes( new_extension_offset_,
new_dimension_offset_,
new_placement_ );
dimension_view_->setAnnotationSide( new_annotation_side_ );
}
void unexecute ( void )
{
dimension_view_ =
dynamic_cast<DimensionView*>( design_book_view_->lookup( db_url_ ) );
dimension_view_->setDimensionAttributes( old_extension_offset_,
old_dimension_offset_,
old_placement_ );
dimension_view_->setAnnotationSide( old_annotation_side_ );
}
void write ( QDomDocument* document ) const
{
QDomElement move_element = document->createElement( lC::STR::MOVE_DIMENSION );
QDomNode root_node = document->firstChild();
if ( !root_node.isNull() )
document->replaceChild( move_element, root_node );
else
document->appendChild( move_element );
move_element.setAttribute( lC::STR::URL, db_url_.toString() );
move_element.setAttribute( lC::STR::OLD_EXTENSION_OFFSET,
lC::format( old_extension_offset_ ) );
move_element.setAttribute( lC::STR::NEW_EXTENSION_OFFSET,
lC::format( new_extension_offset_ ) );
move_element.setAttribute( lC::STR::OLD_DIMENSION_OFFSET,
lC::format( old_dimension_offset_ ) );
move_element.setAttribute( lC::STR::NEW_DIMENSION_OFFSET,
lC::format( new_dimension_offset_ ) );
move_element.setAttribute( lC::STR::OLD_PLACEMENT,
placementText( old_placement_ ) );
move_element.setAttribute( lC::STR::NEW_PLACEMENT,
placementText( new_placement_ ) );
move_element.setAttribute( lC::STR::OLD_ANNOTATION_SIDE,
annotationSideText( old_annotation_side_ ) );
move_element.setAttribute( lC::STR::NEW_ANNOTATION_SIDE,
annotationSideText( new_annotation_side_ ) );
}
};
DimensionModifyInput::DimensionModifyInput ( ConstrainedLine* dimension,
DimensionView* dimension_view )
: selection_type_( TRANSIENT, FIGURE ),
dimensioned_line_( dimension ), dimension_view_( dimension_view ),
old_extension_offset_( 0 ), free_( false )
{}
void DimensionModifyInput::startDisplay ( QMenu* /*context_menu*/ )
{
free_ = false;
}
void DimensionModifyInput::mousePrepress ( QMouseEvent* me,
const SelectedNames& selected )
{
SelectedNames::const_iterator f;
if ( selected.empty() ) {
dimension_view_->parent()->view()->unsetCursor();
return;
}
// For each highlighted figure view
for ( f = selected.begin(); f != selected.end(); ++f ) {
// If the highlighted figure view is *this* view
if ( (*f).second[0] == dimension_view_->parent()->selectionName() ) {
// If this is referring to me
if ( (*f).second.size() > 1 &&
(*f).second[1] == dimension_view_->selectionName() ) {
// If the mouse is over the text box, display the all-ways resize
// cursor (otherwise, the user is only allowed to change the extension
// line offset).
if ( (*f).second.size() > 2 ) {
dimension_view_->parent()->view()->setCursor( Qt::SizeAllCursor );
free_ = true;
}
else {
dimension_view_->parent()->view()->
setCursor( dimension_view_->cursorShape() );
free_ = false;
}
me->accept();
}
else {
dimension_view_->parent()->view()->unsetCursor();
}
return;
}
}
// The dimension view's parent was not highlighted.
dimension_view_->parent()->view()->unsetCursor();
}
void DimensionModifyInput::mousePress ( QMouseEvent* me,
const SelectedNames& selected )
{
// Let the Page handle these events
if ( me->button() != Qt::LeftButton || selected.empty() ) {
me->ignore();
return;
}
SelectedNames::const_iterator f;
for ( f = selected.begin(); f != selected.end(); ++f ) {
// Make sure that it is our figure which is selected
if ( (*f).second[0] == dimension_view_->parent()->selectionName() ) {
// and that we are really selected
if ( (*f).second.size() > 1 &&
(*f).second[1] == dimension_view_->selectionName() ) {
start_pnt_ = dimension_view_->parent()->view()->unproject2D( me->pos() );
last_pnt_ = start_pnt_;
old_extension_offset_ = dimension_view_->extensionOffset();
old_dimension_offset_ = dimension_view_->dimensionOffset();
old_placement_ = dimension_view_->placement();
selection_type_ = SelectionType( TRANSIENT, NONE );
return;
}
}
}
// If this wasn't highlighted, then also let the page handle it.
me->ignore();
return;
}
void DimensionModifyInput::mouseDrag ( QMouseEvent* me,
const SelectedNames& /*selected*/ )
{
current_pnt_ = dimension_view_->parent()->view()->unproject2D( me->pos() );
UnitsBasis::instance()->round( current_pnt_ );
bool ok = dimension_view_->adjust( free_, last_pnt_, current_pnt_ );
if ( ok )
last_pnt_ = current_pnt_;
dimension_view_->parent()->parent()->figureModified();
}
bool DimensionModifyInput::mouseRelease ( QMouseEvent* me,
const SelectedNames& selected )
{
(void)me;
(void)selected;
// Only record an event if the dimension actually moved.
if ( dimension_view_->extensionOffset() != old_extension_offset_ ) {
CommandHistory::instance().
addCommand( new MoveDimensionCommand( "move dimension",
dimension_view_,
old_extension_offset_,
dimension_view_->extensionOffset(),
old_dimension_offset_,
dimension_view_->dimensionOffset(),
old_placement_,
dimension_view_->placement(),
dimension_view_->annotationSide(),
dimension_view_->annotationSide() ) );
}
selection_type_ = SelectionType( TRANSIENT, FIGURE );
return false;
}
void DimensionModifyInput::mouseDoubleClick ( QMouseEvent* me )
{
(void)me;
dimension_view_->editInformation();
}
void DimensionModifyInput::setDimension ( ConstrainedLine* dimension )
{
dimensioned_line_ = dimension;
}
DimensionInfoDialog* DimensionView::dimension_info_dialog_ = 0;
DimensionView::DimensionView ( ConstrainedLine* dimension,
Curve* from_reference, Curve* to_reference,
lC::Orientation orientation,
lC::AnnotationSide annotation_side,
GLuint selection_name,
FigureView* parent )
: GraphicsView( selection_name ), parent_( parent ), dimensioned_line_( dimension ),
from_reference_( from_reference ), to_reference_( to_reference ),
dimension_( 0 ),
modify_input_( dimension, this ),
orientation_( orientation ), annotation_side_( annotation_side )
{
init();
}
DimensionView::DimensionView ( const QDomElement& xml_rep,
GLuint selection_name, FigureView* parent )
: GraphicsView( selection_name ), parent_( parent ), dimensioned_line_( 0 ),
from_reference_( 0 ), to_reference_( 0 ),
dimension_( 0 ),
modify_input_( 0, this )
{
annotation_side_ = lC::annotationSide( xml_rep.attribute( lC::STR::ANNOTATION_SIDE ) );
orientation_ = lC::orientation( xml_rep.attribute( lC::STR::ORIENTATION ) );
DBURL db_url( xml_rep.attribute( lC::STR::DIMENSION ) );
dimensioned_line_ =
dynamic_cast< ConstrainedLine* >( parent_->model()->lookup( db_url ) );
db_url = xml_rep.attribute( lC::STR::FROM );
from_reference_ =
dynamic_cast< Curve* >( parent_->model()->lookup( db_url ) );
db_url = xml_rep.attribute( lC::STR::TO );
to_reference_ =
dynamic_cast< Curve* >( parent_->model()->lookup( db_url ) );
init();
dimension_->
setDimensionAttributes( xml_rep.attribute( lC::STR::EXTENSION_LINE_OFFSET ).toDouble(),
xml_rep.attribute( lC::STR::DIMENSION_OFFSET ).toDouble(),
Space2D::placement( xml_rep.attribute( lC::STR::PLACEMENT ) ) );
}
DimensionView::~DimensionView ( void )
{}
void DimensionView::init ( void )
{
if ( dimension_info_dialog_ == 0 ) {
dimension_info_dialog_ =
new DimensionInfoDialog( parent()->parent()->lCMW() );
// Create invisible button groups connecting the Left/Right Above/Below
// radio buttons, respectively.
QGroupBox* h = new QGroupBox( dimension_info_dialog_->getUi()->GroupBox1);
QHBoxLayout* hw = new QHBoxLayout ( h );
h->setObjectName("H");
hw->addWidget( dimension_info_dialog_->getUi()->leftButton );
hw->addWidget( dimension_info_dialog_->getUi()->rightButton );
h->setLayout( hw );
h->hide();
QGroupBox* v = new QGroupBox( dimension_info_dialog_->getUi()->GroupBox1 );
QHBoxLayout* vw = new QHBoxLayout( v );
v->setObjectName( "V" );
vw->addWidget( dimension_info_dialog_->getUi()->aboveButton );
vw->addWidget( dimension_info_dialog_->getUi()->belowButton );
v->setLayout( vw );
v->hide();
dimension_info_dialog_->getUi()->offsetLengthSpinBox->
setLengthLimits( UnitsBasis::instance()->lengthUnit(),
UnitsBasis::instance()->format(),
UnitsBasis::instance()->precision(),
lC::MINIMUM_DIMESION, lC::MAXIMUM_DIMENSION, 0 );
}
computeLayout();
}
QString DimensionView::name ( void ) const
{
return dimensioned_line_->name();
}
DBURL DimensionView::dbURL ( void ) const
{
return dimensioned_line_->dbURL();
}
void DimensionView::setName ( const QString& name )
{
DBURL old_db_url = dimensioned_line_->dbURL();
dimensioned_line_->setName( name );
CommandHistory::instance().
addCommand( new RenameCommand( "rename dimension", parent()->model(),
old_db_url, dimensioned_line_->dbURL() ) );
}
void DimensionView::setAnnotationSide ( lC::AnnotationSide annotation_side )
{
annotation_side_ = annotation_side;
computeLayout();
}
void DimensionView::setReferences ( Curve* from_reference, Curve* to_reference )
{
from_reference_ = from_reference;
to_reference_ = to_reference;
computeLayout();
}
void DimensionView::editInformation ( void )
{
QString length_str = QString::number( fabs( dimensioned_line_->offset() ) );
dimension_info_dialog_->getUi()->nameEdit->
setText( lC::formatName( dimensioned_line_->name() ) );
dimension_info_dialog_->getUi()->nameEdit->selectAll();
dimension_info_dialog_->getUi()->toReferenceLineEdit->
setText( lC::formatName( dimensioned_line_->path() ) );
dimension_info_dialog_->getUi()->fromReferenceLineEdit->
setText( lC::formatName( dimensioned_line_->reference()->path() ) );
dimension_info_dialog_->getUi()->offsetLengthSpinBox->
setLengthLimits( UnitsBasis::instance()->lengthUnit(),
UnitsBasis::instance()->format(),
UnitsBasis::instance()->precision(),
lC::MINIMUM_DIMESION, lC::MAXIMUM_DIMENSION,
fabs( dimensioned_line_->offset() ) );
dimension_info_dialog_->getUi()->offsetLengthSpinBox->
setLength( fabs( dimensioned_line_->offset() ) );
switch ( orientation_ ) {
case lC::HORIZONTAL:
dimension_info_dialog_->getUi()->horizontalButton->setChecked( true );
dimension_info_dialog_->getUi()->leftButton->setEnabled( false );
dimension_info_dialog_->getUi()->rightButton->setEnabled( false );
dimension_info_dialog_->getUi()->belowButton->setEnabled( true );
dimension_info_dialog_->getUi()->aboveButton->setEnabled( true );
switch ( annotation_side_ ) {
case lC::ABOVE:
dimension_info_dialog_->getUi()->aboveButton->setChecked( true );
break;
case lC::BELOW:
dimension_info_dialog_->getUi()->belowButton->setChecked( true );
}
break;
case lC::VERTICAL:
dimension_info_dialog_->getUi()->verticalButton->setChecked( true );
dimension_info_dialog_->getUi()->leftButton->setEnabled( true );
dimension_info_dialog_->getUi()->rightButton->setEnabled( true );
dimension_info_dialog_->getUi()->belowButton->setEnabled( false );
dimension_info_dialog_->getUi()->aboveButton->setEnabled( false );
switch ( annotation_side_ ) {
case lC::ABOVE:
dimension_info_dialog_->getUi()->rightButton->setChecked( true );
break;
case lC::BELOW:
dimension_info_dialog_->getUi()->leftButton->setChecked( true );
}
break;
case lC::OTHER:
dimension_info_dialog_->getUi()->otherButton->setChecked( true );
dimension_info_dialog_->getUi()->leftButton->setChecked( false );
dimension_info_dialog_->getUi()->rightButton->setChecked( false );
dimension_info_dialog_->getUi()->belowButton->setChecked( false );
dimension_info_dialog_->getUi()->aboveButton->setChecked( false );
dimension_info_dialog_->getUi()->leftButton->setEnabled( false );
dimension_info_dialog_->getUi()->rightButton->setEnabled( false );
dimension_info_dialog_->getUi()->belowButton->setEnabled( false );
dimension_info_dialog_->getUi()->aboveButton->setEnabled( false );
break;
}
REDO:
// Kind of gets lost in the noise here
int ret = dimension_info_dialog_->exec();
if ( ret == QDialog::Rejected ) return;
bool modified = false;
if ( dimension_info_dialog_->getUi()->nameEdit->isModified() ) {
#if 0
if ( !setName( dimension_info_dialog_->nameEdit->text() ) )
goto REDO;
#else
if ( dimensioned_line_->parent()->uniqueGeometryName( dimensioned_line_,
dimension_info_dialog_->getUi()->
nameEdit->text() ) )
setName( dimension_info_dialog_->getUi()->nameEdit->text() );
else {
QMessageBox mb( trC( lC::STR::LIGNUMCAD ),
qApp->translate( "Space2D::DimensionView",
"The name \"%1\" for a geometry of type %2 already exists\n"
"as a child of %3." ).
arg( dimension_info_dialog_->getUi()->nameEdit->text() ).
arg( trC( dimensioned_line_->type() ) ).
arg( dimensioned_line_->parent()->name() ),
QMessageBox::Information,
QMessageBox::Yes | QMessageBox::Default,
QMessageBox::Cancel,
QMessageBox::NoButton );
mb.setButtonText( QMessageBox::Yes,
qApp->translate( "Space2D::DimensionView",
"Enter another name" ) );
mb.setButtonText( QMessageBox::Cancel,
qApp->translate( "Space2D::DimensionView",
"Cancel changes" ) );
switch ( mb.exec() ) {
case QMessageBox::Yes:
goto REDO;
case QMessageBox::Cancel:
return;
}
}
#endif
modified = true;
}
if ( dimension_info_dialog_->getUi()->offsetLengthSpinBox->edited() ) {
double old_offset = dimensioned_line_->offset();
if ( dimensioned_line_->offset() >= 0 )
dimensioned_line_->
setOffset( dimension_info_dialog_->getUi()->offsetLengthSpinBox->length() );
else
dimensioned_line_->
setOffset( -dimension_info_dialog_->getUi()->offsetLengthSpinBox->length() );
MoveLinesCommand* move_command = new MoveLinesCommand( "resize dimension",
parent()->model() );
move_command->add( dimensioned_line_, old_offset );
CommandHistory::instance().addCommand( move_command );
modified = true;
}
lC::AnnotationSide old_annotation_side = annotation_side_;
bool annotation_side_modified = false;
switch ( orientation_ ) {
case lC::HORIZONTAL:
if ( dimension_info_dialog_->getUi()->aboveButton->isChecked() &&
annotation_side_ == lC::BELOW ) {
annotation_side_ = lC::ABOVE;
computeLayout();
annotation_side_modified = true;
}
else if ( dimension_info_dialog_->getUi()->belowButton->isChecked() &&
annotation_side_ == lC::ABOVE ) {
annotation_side_ = lC::BELOW ;
computeLayout();
annotation_side_modified = true;
}
break;
case lC::VERTICAL:
if ( dimension_info_dialog_->getUi()->rightButton->isChecked() &&
annotation_side_ == lC::BELOW ) {
annotation_side_ = lC::ABOVE;
computeLayout();
annotation_side_modified = true;
}
else if ( dimension_info_dialog_->getUi()->leftButton->isChecked() &&
annotation_side_ == lC::ABOVE ) {
annotation_side_ = lC::BELOW;
computeLayout();
annotation_side_modified = true;
}
break;
case lC::OTHER:
// Not sure what to do here. Indicates that the situation may not
// be so complicated. Probably better to have some kind of graphical
// representation of the annotation side, anyway.
break;
}
if ( annotation_side_modified )
CommandHistory::instance().
addCommand( new MoveDimensionCommand( "move dimension",
this,
dimension_->extensionOffset(),
dimension_->extensionOffset(),
dimension_->dimensionOffset(),
dimension_->dimensionOffset(),
dimension_->placement(),
dimension_->placement(),
old_annotation_side,
annotation_side_ ) );
if ( modified ) parent()->parent()->figureModified();
}
void DimensionView::draw ( void ) const
{
lC::Render::Mode mode = lC::Render::REGULAR;
if ( isActivated() )
mode = lC::Render::ACTIVATED;
else if ( isHighlighted() )
mode = lC::Render::HIGHLIGHTED;
dimension_->draw( mode );
}
void DimensionView::select ( SelectionType selection_type ) const
{
if ( selection_type.entity_ != FIGURE ) return;
glPushName( selectionName() );
lC::Render::Mode mode = lC::Render::REGULAR;
if ( isActivated() )
mode = lC::Render::ACTIVATED;
else if ( isHighlighted() )
mode = lC::Render::HIGHLIGHTED;
dimension_->select( mode );
glPopName();
}
void DimensionView::setDimensionAttributes ( double extension_offset,
double dimension_offset,
enum Dimension::Placement placement )
{
dimension_->setDimensionAttributes( extension_offset, dimension_offset,
placement );
}
double DimensionView::extensionOffset ( void ) const
{
return dimension_->extensionOffset();
}
double DimensionView::dimensionOffset ( void ) const
{
return dimension_->dimensionOffset();
}
enum Dimension::Placement DimensionView::placement ( void ) const
{
return dimension_->placement();
}
void DimensionView::computeLayout ( void )
{
Point end0 = dimensioned_line_->reference()->intersect( from_reference_ );
Point end1 = dimensioned_line_->intersect( to_reference_ );
Vector normal;