2 #include <qpushbutton.h>
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>
18 #include "ObjectDlg.h"
21 //////////////////////////////////////////////////////////////////////
22 // Construction/Destruction
23 //////////////////////////////////////////////////////////////////////
25 ObjectDlg::ObjectDlg( QWidget* parent, Handle(V3d_View)& view,
26 Handle(AIS_InteractiveContext)& cxt )
28 myAutoApply( true ), myView( view ), myContext( cxt )
31 setWindowTitle( tr( "TITLE_OBJECT_DLG" ) );
33 QVBoxLayout* topLayout = new QVBoxLayout( this );
34 topLayout->setMargin( 5 );
36 QFrame* mainFrame = new QFrame( this );
37 mainFrame->setFrameStyle( QFrame::Box | QFrame::Sunken );
38 topLayout->addWidget( mainFrame );
39 topLayout->addSpacing( 10 );
42 QGridLayout* pLayout = new QGridLayout( mainFrame );
43 pLayout->setMargin( 5 );
44 myDegModelLabel = new QLabel( tr("MEN_DLG_DEGMODEL"), mainFrame );
45 myDegRatioLabel = new QLabel( tr("MEN_DLG_DEGRATIO"), mainFrame );
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 ) ) ) );
57 //QSpinBox* degRatioSpin = new QSpinBox( mainFrame );
58 //QSpinBox ( QWidget * parent = 0, const char * name = 0 )
59 myDegRatioSpin = new QSpinBox( mainFrame );
60 myDegRatioSpin->setRange(0, 10);
61 myDegRatioSpin->setSingleStep(1);
62 verify( connect( myDegRatioSpin, SIGNAL( valueChanged( int ) ), SLOT( onDegRatio( int ) ) ) );
64 QCheckBox* showEdges = new QCheckBox( mainFrame );
65 showEdges->setText( tr( "BTN_SHOWEDGES" ) );
66 verify( connect( showEdges, SIGNAL( toggled( bool ) ), SLOT( onShowEdges( bool ) ) ) );
68 myEdgeStyle = new QLabel( tr("MEN_DLG_EDGESTYLE"), mainFrame );
69 myEdgeWidth = new QLabel( tr("MEN_DLG_EDGEWIDTH"), mainFrame );
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 ) ) ) );
79 //myEdgeSpin = new QSpinBox( mainFrame );
80 myEdgeSpin = new QSpinBox( mainFrame );
81 myEdgeSpin->setRange(1, 10);
82 myEdgeSpin->setSingleStep(10);
83 verify( connect( myEdgeSpin, SIGNAL( valueChanged( int ) ), SLOT( onEdgeWidth( int ) ) ) );
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 );
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 ) ) ) );
106 QHBoxLayout* applyLayout = new QHBoxLayout();
107 applyLayout->addWidget( autoApply );
108 applyLayout->addStretch( 10 );
109 topLayout->addLayout(applyLayout);
110 topLayout->addSpacing( 10 );
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() ) ) );
118 // bHelp = new QPushButton( tr( "BTN_HELP" ), this );
119 // verify( connect( bHelp, SIGNAL( clicked() ), SLOT( onHelp() ) ) );
121 QHBoxLayout* btnLayout = new QHBoxLayout();
122 btnLayout->setSpacing( 5 );
123 btnLayout->addStretch( 10 );
124 btnLayout->addWidget( bOk );
125 btnLayout->addWidget( bCancel );
126 btnLayout->addStretch( 10 );
127 // btnLayout->addWidget( bHelp );
128 topLayout->addLayout(btnLayout);
130 QSize s = topLayout->totalMinimumSize();
131 s.setWidth( s.width() + topLayout->margin() + 10 );
132 s.setHeight( s.height() + topLayout->margin() + 10 );
136 ObjectDlg::~ObjectDlg()
140 void ObjectDlg::showEvent ( QShowEvent* e )
142 QWidget::showEvent( e );
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 );
153 void ObjectDlg::onOk()
158 void ObjectDlg::onCancel()
163 void ObjectDlg::onHelp()
167 void ObjectDlg::onShowEdges( bool on )
170 myEdgeStyle->setEnabled( on );
171 myEdgeWidth->setEnabled( on );
172 myEdgeBox->setEnabled( on );
173 myEdgeSpin->setEnabled( on );
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();
182 aspect->Aspect()->SetEdgeOn();
184 aspect->Aspect()->SetEdgeOff();
185 object->SetAspect( aspect );
187 //myContext->UpdateCurrentViewer();
192 void ObjectDlg::onDegenerateModel( int index )
194 if ( myCurrentDegModel != index ) {
198 myDegModel = Aspect_TDM_NONE;
201 myDegModel = Aspect_TDM_TINY;
204 myDegModel = Aspect_TDM_WIREFRAME;
207 myDegModel = Aspect_TDM_MARKER;
210 myDegModel = Aspect_TDM_BBOX;
213 myCurrentDegModel = index;
214 updateDegenerationModel();
218 void ObjectDlg::onDegRatio( int ratio )
220 myCurrentDegRatio = ratio / 10.;
221 updateDegenerationModel();
224 void ObjectDlg::onEdgeStyle( int index )
226 if ( myCurrentEdgeStyle != index ) {
227 myCurrentEdgeStyle = index;
228 updateEdgeAspect( true );
232 void ObjectDlg::onEdgeWidth( int value )
234 myCurrentEdgeWidth = (float) value;
235 updateEdgeAspect( false );
238 void ObjectDlg::onAutoApply( bool on )
243 void ObjectDlg::updateEdgeAspect( bool edgeStyle )
245 Aspect_TypeOfLine type;
247 switch( myCurrentEdgeStyle ) {
249 type = Aspect_TOL_SOLID;
252 type = Aspect_TOL_DASH;
255 type = Aspect_TOL_DOT;
258 type = Aspect_TOL_DOTDASH;
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();
268 aspect->Aspect()->SetEdgeLineType( type );
270 aspect->Aspect()->SetEdgeWidth( myCurrentEdgeWidth );
271 object->SetAspect( aspect );
274 //myContext->UpdateCurrentViewer();
275 myView->Viewer()->Update();
278 void ObjectDlg::updateDegenerationModel()
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 );
286 //myView->SetAnimationModeOn();
290 myContext->UpdateCurrentViewer();