Moka Ihm Qt
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
creation-brin.qt.cc
Go to the documentation of this file.
1 /*
2  * Moka : Un modeleur de 3-G-cartes.
3  * Copyright (C) 2004, Moka Team, Université de Poitiers, Laboratoire SIC
4  * http://www.sic.sp2mi.univ-poitiers.fr/
5  * Copyright (C) 2009, Guillaume Damiand, CNRS, LIRIS,
6  * guillaume.damiand@liris.cnrs.fr, http://liris.cnrs.fr/
7  *
8  * This file is part of Moka
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #include "creation-brin.qt.hh"
25 #include "window.qt.hh"
26 #include "HtmlEntities.hh"
27 #include "SpaceWidget.qt.hh"
28 
29 #include <QtGui/QPixmap>
30 #include <QtGui/QLabel>
31 
32 
33 /*******************************************************************/
34 /* CLASSE creationBrin */
35 /*******************************************************************/
36 
37 // Constructeur
38 //-------------
39 
41  GMap3d :: CControlerGMap * controler ) :
42  CreationObjet(parent , HTML::decode("Creation Dart/Polyline/Face" ),
43  controler ),
44  FSouris ( false )
45 {
46  //************ Creation des widgets ***********
47 
48  FAffX = new QLabel ( " X : " ) ;
49  FSaisieX = new FloatSpinBox ( 0.5 , -1000 ,1000 , 2 , 0.1 ) ;
50  FAffY = new QLabel ( " Y : " ) ;
51  FSaisieY = new FloatSpinBox ( 0.5 , -1000 ,1000 , 2 , 0.1 ) ;
52  FAffZ = new QLabel ( " Z : " ) ;
53  FSaisieZ = new FloatSpinBox ( 0.5 , -1000 ,1000 , 2 , 0.1 ) ;
54 
55  addWidget(new QLabel ( " Position : " ));
56  addWidget(FAffX);
57  addWidget(FSaisieX);
58  addWidget(FAffY);
59  addWidget(FSaisieY);
60  addWidget(FAffZ);
61  addWidget(FSaisieZ);
62  addWidget(new SpaceWidget(SPACE_PIX_SIZE,1));
63 
64  //*********** Creation des boutons **************
65  QIcon p1 ( ":/boutonCreer.png" ) ;
66  QIcon p2 ( ":/boutonSupprimer.png" ) ;
67 
68  FNouveau = new QPushButton ( p1 , *HTML::decode("Create new") ,
69  this ) ;
70  FSupprimer = new QPushButton ( p2 , "Delete last" , this ) ;
71 
72  QObject::connect ( FNouveau , SIGNAL ( clicked ( ) ) , this,
73  SLOT ( prolong ( ) ) ) ;
74  QObject::connect ( FSupprimer , SIGNAL ( clicked ( ) ) , this,
75  SLOT (shorten ( ) ) ) ;
76 
77  addWidget(FNouveau);
78  addWidget(FSupprimer);
79  addWidget(new SpaceWidget(SPACE_PIX_SIZE,1));
80 
81  FChoix = new BoutonsCreation ( this ) ;
82  FChoix -> getOptions ( ) -> setEnabled ( false ) ;
83 
84  clearLastVertex( ) ;
85  FChoix -> reinit ( ) ;
86  update ( ) ;
87 
88  // Ecoutes
89  QObject::connect ( FSaisieX , SIGNAL ( valueChanged ( double ) ) , this,
90  SLOT ( lastVertexChanged ( ) ) ) ;
91  QObject::connect ( FSaisieY , SIGNAL ( valueChanged ( double ) ) , this,
92  SLOT ( lastVertexChanged ( ) ) ) ;
93  QObject::connect ( FSaisieZ , SIGNAL ( valueChanged ( double ) ) , this,
94  SLOT ( lastVertexChanged ( ) ) ) ;
95 }
96 
97 // Destructeur
98 //------------
99 
101 
103 {
104  FSouris = true ;
105  if ( FControler -> getParameterPolylinePosition() -> getNbVertices() > 0 )
106  setNewVertex ( FControler ->
107  getParameterPolylinePosition() ->
108  getLastVertex() );
109  else
110  clearLastVertex();
111  FSouris = false ;
112 }
113 
114 
115 // Accesseurs en ecriture
116 //------------------------
117 void CreationBrin :: setNewVertex ( const CVertex & v )
118 {
119  // On se met en mode souris
120  FSouris = true ;
121 
122  FSaisieX -> setValuef ( v . getX ( ) ) ;
123  FSaisieY -> setValuef ( v . getY ( ) ) ;
124  FSaisieZ -> setValuef ( v . getZ ( ) ) ;
125 
126  FSouris = false ;
127 }
128 
129 void CreationBrin :: clearLastVertex ( )
130 {
131  FSaisieX -> setValuef ( 0 ) ;
132  FSaisieY -> setValuef ( 0 ) ;
133  FSaisieZ -> setValuef ( 0 ) ;
134 }
135 
136 void CreationBrin :: lastVertexChanged ( )
137 {
138  if ( ! FSouris )
139  {
140  CVertex vertex ( FSaisieX -> valuef ( ) ,
141  FSaisieY -> valuef ( ) ,
142  FSaisieZ -> valuef ( ) ) ;
143 
144  if (FControler -> getParameterPolylinePosition()->getNbVertices()==0)
145  FControler -> getParameterPolylinePosition()->addVertex(vertex);
146  else
147  FControler -> getParameterPolylinePosition()->setLastVertex(vertex);
148  repaint ( ) ;
149  }
150 }
151 
152 // SLOTS
153 //-------
154 void CreationBrin :: close ( )
155 {
156  // TODO getDialogWindow()->getViewsWindow()->polylineClose();
157 }
158 
159 void CreationBrin :: prolong ( )
160 {
161  CVertex vertex( FSaisieX -> valuef ( ) ,
162  FSaisieY -> valuef ( ) ,
163  FSaisieZ -> valuef ( ) ) ;
164 
165  FControler -> getParameterPolylinePosition ( ) -> addVertex ( vertex ) ;
166  update ( ) ;
167  repaint ( ) ;
168 }
169 
170 void CreationBrin :: shorten ( )
171 {
172  if (FControler -> getParameterPolylinePosition( ) -> getNbVertices ( ) > 0 )
173  {
174  FControler -> getParameterPolylinePosition ( ) -> removeLastVertex ( ) ;
175  update ( ) ;
176  repaint ( ) ;
177  }
178 }
179