00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "controler-gmap.hh"
00026 #include "parameter-object-translation.hh"
00027 #include "parameter-object-rotation.hh"
00028 #include "parameter-object-scale.hh"
00029 #include "parameter-object-ponderation.hh"
00030 #include "parameter-selection.hh"
00031 #include "view-precompile.hh"
00032 #include "vertex.hh"
00033 #include "vector.hh"
00034 #include "g-map-vertex.hh"
00035 #include "geometry.hh"
00036 using namespace GMap3d;
00037
00038 void CControlerGMap::setObjectTranslationVector(const CVertex & AVector)
00039 {
00040 if ( AVector!= FParameterTranslation->getVector() )
00041 {
00042 FParameterTranslation->setVector(AVector);
00043 if (FCurrentMode==MODE_TRANSLATION)
00044 {
00045 FMap->translate(FDeformationMark, AVector,
00046 FDirectInfoVertex, FDirectInfoPonderation);
00047 setPartialModelChanged();
00048 }
00049 }
00050 }
00051
00052 CVertex CControlerGMap::getObjectTranslationVector() const
00053 { return FParameterTranslation->getVector(); }
00054
00055 void CControlerGMap::setObjectTranslationPonderation(bool AActive)
00056 {
00057 if (FParameterTranslation->getPonderation()!=AActive)
00058 {
00059 FParameterTranslation->setPonderation(AActive);
00060 if (FCurrentMode==MODE_TRANSLATION)
00061 {
00062 if (FParameterTranslation->getPonderation())
00063 {
00064 addPonderationCoefs();
00065 updatePonderationCoefs();
00066 }
00067 else
00068 delPonderationCoefs();
00069
00070 FMap->updateDirectInfoWithVertex(FDirectInfoVertex);
00071 }
00072 }
00073 }
00074
00075 bool CControlerGMap::getObjectTranslationPonderation() const
00076 { return FParameterTranslation->getPonderation(); }
00077
00078 void CControlerGMap::toggleObjectTranslationPonderation()
00079 { setObjectTranslationPonderation(!getObjectTranslationPonderation()); }
00080
00081 void CControlerGMap::setObjectRotationAxeVertex(const CVertex & AAxeVertex)
00082 {
00083 if ( FCurrentModeOperation==MODE_OPERATION_NONE )
00084 {
00085 FParameterRotation->setAxeVertex(AAxeVertex);
00086 FParameterRotation->setAngle(0.0);
00087 }
00088 }
00089
00090 CVertex CControlerGMap::getObjectRotationAxeVertex() const
00091 { return FParameterRotation->getAxeVertex(); }
00092
00093 void CControlerGMap::setObjectRotationAxeVector(const CVertex & AAxeVector)
00094 {
00095 if ( FCurrentModeOperation==MODE_OPERATION_NONE )
00096 {
00097 FParameterRotation->setAxeVector(AAxeVector);
00098 FParameterRotation->setAngle(0.0);
00099 }
00100 }
00101
00102 CVertex CControlerGMap::getObjectRotationAxeVector() const
00103 { return FParameterRotation->getAxeVector(); }
00104
00105 void CControlerGMap::setObjectRotationAngle(float AAngle)
00106 {
00107 if (AAngle!=FParameterRotation->getAngle())
00108 {
00109 FParameterRotation->setAngle(AAngle);
00110 if (FCurrentMode==MODE_ROTATION)
00111 {
00112 FMap->rotate(FDeformationMark, FParameterRotation->getAxeVertex(),
00113 FParameterRotation->getAxeVector(),
00114 AAngle, FDirectInfoVertex, FDirectInfoPonderation);
00115 setPartialModelChanged();
00116 }
00117 }
00118 }
00119
00120 float CControlerGMap::getObjectRotationAngle() const
00121 { return FParameterRotation->getAngle(); }
00122
00123 void CControlerGMap::setObjectRotationPonderation(bool AActive)
00124 {
00125 if (FParameterRotation->getPonderation()!=AActive)
00126 {
00127 FParameterRotation->setPonderation(AActive);
00128 if (FCurrentMode==MODE_ROTATION)
00129 {
00130 if (FParameterRotation->getPonderation())
00131 {
00132 addPonderationCoefs();
00133 updatePonderationCoefs();
00134 }
00135 else
00136 delPonderationCoefs();
00137
00138 FMap->updateDirectInfoWithVertex(FDirectInfoVertex);
00139 }
00140 }
00141 }
00142
00143 bool CControlerGMap::getObjectRotationPonderation() const
00144 { return FParameterRotation->getPonderation(); }
00145
00146 void CControlerGMap::toggleObjectRotationPonderation()
00147 { setObjectRotationPonderation(!getObjectRotationPonderation()); }
00148
00149 void CControlerGMap::setObjectScaleType(TScaleType AScaleType)
00150 {
00151 if ( FCurrentModeOperation==MODE_OPERATION_NONE )
00152 {
00153 FParameterScale->setScaleType(AScaleType);
00154 }
00155 }
00156
00157 TScaleType CControlerGMap::getObjectScaleType() const
00158 { return FParameterScale->getScaleType(); }
00159
00160 void CControlerGMap::setObjectScaleIso(bool AValue)
00161 {
00162 if ( AValue!=FParameterScale->getIsoScale() )
00163 {
00164 FParameterScale->setIsoScale(AValue);
00165 FParameterScale->setIsoCoef(1.0);
00166
00167 FMap->updateDirectInfoWithVertex(FDirectInfoVertex);
00168 }
00169 }
00170
00171 bool CControlerGMap::getObjectScaleIso() const
00172 { return FParameterScale->getIsoScale(); }
00173
00174 void CControlerGMap::toggleObjectScaleIso()
00175 { setObjectScaleIso(!getObjectScaleIso()); }
00176
00177 void CControlerGMap::setObjectScaleCenter(const CVertex & ACenter)
00178 {
00179 if ( FCurrentModeOperation==MODE_OPERATION_NONE )
00180 {
00181 FParameterScale->setCenter(ACenter);
00182 }
00183 }
00184
00185 CVertex CControlerGMap::getObjectScaleCenter() const
00186 { return FParameterScale->getCenter(); }
00187
00188 void CControlerGMap::setObjectScaleVector(const CVertex & AVector)
00189 {
00190 if ( FCurrentModeOperation==MODE_OPERATION_NONE )
00191 {
00192 FParameterScale->setVector(AVector);
00193 }
00194 }
00195
00196 CVertex CControlerGMap::getObjectScaleVector() const
00197 { return FParameterScale->getVector(); }
00198
00199 void CControlerGMap::setObjectScaleIsoCoef(float AValue)
00200 {
00201 if ( AValue!=FParameterScale->getIsoCoef() )
00202 {
00203 FParameterScale->setIsoCoef(AValue);
00204 if (FCurrentMode==MODE_SCALE)
00205 {
00206 FMap->scale(FDeformationMark, FParameterScale->getCenter(),
00207 CVertex(AValue,AValue,AValue),
00208 FDirectInfoVertex, FDirectInfoPonderation);
00209 setPartialModelChanged();
00210 }
00211 }
00212 }
00213
00214 float CControlerGMap::getObjectScaleIsoCoef() const
00215 { return FParameterScale->getIsoCoef(); }
00216
00217 void CControlerGMap::setObjectScaleCoef(const CVertex & AValue)
00218 {
00219 if ( AValue!=FParameterScale->getCoef() )
00220 {
00221 FParameterScale->setCoef(AValue);
00222 if (FCurrentMode==MODE_SCALE)
00223 {
00224 FMap->scale(FDeformationMark, FParameterScale->getCenter(),
00225 AValue, FDirectInfoVertex, FDirectInfoPonderation);
00226 setPartialModelChanged();
00227 }
00228 }
00229 }
00230
00231 CVertex CControlerGMap::getObjectScaleCoef() const
00232 { return FParameterScale->getCoef(); }
00233
00234 void CControlerGMap::setObjectScaleCoef(int ADim, float AValue)
00235 {
00236 if ( AValue!=FParameterScale->getCoef(ADim) )
00237 {
00238 FParameterScale->setCoef(ADim,AValue);
00239 if (FCurrentMode==MODE_SCALE)
00240 {
00241 FMap->scale(FDeformationMark, FParameterScale->getCenter(),
00242 getObjectScaleCoef(), FDirectInfoVertex,
00243 FDirectInfoPonderation);
00244 setPartialModelChanged();
00245 }
00246 }
00247 }
00248
00249 float CControlerGMap::getObjectScaleCoef(int ADim) const
00250 { return FParameterScale->getCoef(ADim); }
00251
00252 void CControlerGMap::setObjectScalePonderation(bool AActive)
00253 {
00254 if (FParameterScale->getPonderation()!=AActive)
00255 {
00256 FParameterScale->setPonderation(AActive);
00257 if (FCurrentMode==MODE_SCALE)
00258 {
00259 if (FParameterScale->getPonderation())
00260 {
00261 addPonderationCoefs();
00262 updatePonderationCoefs();
00263 }
00264 else
00265 delPonderationCoefs();
00266
00267 FMap->scale(FDeformationMark, FParameterScale->getCenter(),
00268 FParameterScale->getCoef(), FDirectInfoVertex,
00269 FDirectInfoPonderation);
00270 setPartialModelChanged();
00271 }
00272 }
00273 }
00274
00275 bool CControlerGMap::getObjectScalePonderation() const
00276 { return FParameterScale->getPonderation(); }
00277
00278 void CControlerGMap::toggleObjectScalePonderation()
00279 { setObjectScalePonderation(!getObjectScalePonderation()); }
00280
00281 void CControlerGMap::modeObjectTransformationBegin(bool APonderation)
00282 {
00283 FDeformationDone = false;
00284 basicPreSave();
00285 FDeformationMark = getSelectionMark();
00286
00287 FDirectInfoVertex = FMap->getNewDirectInfo();
00288 FMap->duplicateVertexToDirectInfo(FDeformationMark, FDirectInfoVertex);
00289
00290 assert(getParameterGMapVertex()->getMarkPartialChanged() == -1);
00291 getParameterGMapVertex()->setMarkPartialChanged(FMap->getNewMark());
00292
00293 FMap->markIncidentCells(ORBIT_VOLUME, FDeformationMark,
00294 getParameterGMapVertex()->getMarkPartialChanged());
00295 FMap->markIncidentCells(ORBIT_VERTEX,
00296 getParameterGMapVertex()->getMarkPartialChanged());
00297 FMap->markIncidentCells(ORBIT_VOLUME,
00298 getParameterGMapVertex()->getMarkPartialChanged());
00299
00300 if (APonderation)
00301 {
00302 addPonderationCoefs();
00303 updatePonderationCoefs();
00304 }
00305
00306 for (unsigned int i=0; i<FViews.size(); ++i)
00307 viewEnableObjectTransformationPrecompile(i);
00308 }
00309
00310 void CControlerGMap::modeTranslationBegin()
00311 {
00312 modeObjectTransformationBegin(FParameterTranslation->getPonderation());
00313 setMessage("Mode translation");
00314 FParameterTranslation->setVector(ORIGIN);
00315 }
00316
00317 void CControlerGMap::modeRotationBegin()
00318 {
00319 modeObjectTransformationBegin(FParameterRotation->getPonderation());
00320 setMessage("Mode rotation");
00321 CVertex bary = FMap->directInfoBarycenter(FDirectInfoVertex);
00322 FParameterRotation->setAxeVertex(bary);
00323 }
00324
00325 void CControlerGMap::modeScaleBegin()
00326 {
00327 modeObjectTransformationBegin(FParameterScale->getPonderation());
00328 setMessage("Mode homothétie");
00329 FParameterScale->setIsoCoef(1.0);
00330 FParameterScale->setCenter(FMap->directInfoBarycenter(FDirectInfoVertex));
00331 }
00332
00333 void CControlerGMap::modeObjectTransformationEnd(bool APonderation)
00334 {
00335 FMap->deleteDuplicatedVertex(FDirectInfoVertex);
00336 FMap->freeDirectInfo(FDirectInfoVertex);
00337
00338 FMap->unmarkAll(getParameterGMapVertex()->getMarkPartialChanged());
00339 FMap->freeMark(getParameterGMapVertex()->getMarkPartialChanged());
00340 getParameterGMapVertex()->setMarkPartialChanged(-1);
00341
00342 if (APonderation)
00343 delPonderationCoefs();
00344
00345 for (unsigned int i=0; i<FViews.size(); ++i)
00346 viewDisableObjectTransformationPrecompile(i);
00347
00348 if (FDeformationDone)
00349 basicPostSaveOk();
00350 else
00351 basicPostSaveFailed();
00352 }
00353
00354 void CControlerGMap::modeTranslationEnd()
00355 {
00356 modeObjectTransformationEnd(FParameterTranslation->getPonderation());
00357 }
00358
00359 void CControlerGMap::modeRotationEnd()
00360 {
00361 modeObjectTransformationEnd(FParameterRotation->getPonderation());
00362 }
00363
00364 void CControlerGMap::modeScaleEnd()
00365 {
00366 modeObjectTransformationEnd(FParameterScale->getPonderation());
00367 }
00368
00369 void CControlerGMap::modeTranslationOperationStart()
00370 {
00371 CViewPrecompile * view = FViews[FCurrentViewId];
00372 assert(view != NULL);
00373
00374 view->unproject(FFirstX, FFirstY, FFirst3D);
00375
00376 FMap->updateDirectInfoWithVertex(FDirectInfoVertex);
00377 }
00378
00379 void CControlerGMap::modeRotationOperationStart()
00380 {
00381 CViewPrecompile * view = FViews[FCurrentViewId];
00382 assert(view != NULL);
00383
00384 view->unproject(FFirstX, FFirstY, FFirst3D);
00385
00386 FParameterRotation->setAxeVector(view->getEyeDirection());
00387
00388 FMap->updateDirectInfoWithVertex(FDirectInfoVertex);
00389 }
00390
00391 void CControlerGMap::modeScaleOperationStart()
00392 {
00393 CViewPrecompile * view = FViews[FCurrentViewId];
00394 assert(view != NULL);
00395
00396 view->unproject(FFirstX, FFirstY, FFirst3D);
00397
00398 FMap->updateDirectInfoWithVertex(FDirectInfoVertex);
00399 }
00400
00401 void CControlerGMap::modeTranslationOperationMove()
00402 {
00403 float last3D[3];
00404 FViews[FCurrentViewId]->unproject(FLastX , FLastY , last3D);
00405
00406 CVertex vect= CVertex(last3D[0], last3D[1], last3D[2]) -
00407 CVertex(FFirst3D[0], FFirst3D[1], FFirst3D[2]);
00408
00409 FDeformationDone |= !vect.isNull();
00410 setObjectTranslationVector(vect);
00411 }
00412
00413 void CControlerGMap::modeRotationOperationMove()
00414 {
00415 float last3D[3];
00416 FViews[FCurrentViewId]->unproject(FLastX , FLastY , last3D);
00417
00418 CVertex R =
00419 CGeometry::orthoProjectVertexOnPlane(FParameterRotation->getAxeVertex(),
00420 FViews[FCurrentViewId]->getLookAt(),
00421 FViews[FCurrentViewId]->getEyeDirection());
00422
00423 float newAngle = CGeometry::getAngle(CVertex(FFirst3D[0], FFirst3D[1], FFirst3D[2])-R,
00424 CVertex(last3D[0], last3D[1], last3D[2])-R,
00425 FViews[FCurrentViewId]->getEyeDirection());
00426
00427 FDeformationDone |= !isZero(newAngle);
00428 setObjectRotationAngle(newAngle);
00429 }
00430
00431 void CControlerGMap::modeScaleOperationMove()
00432 {
00433 CViewPrecompile * view = FViews[FCurrentViewId];
00434
00435 if (FParameterScale->getIsoScale())
00436 {
00437 float coef = (FLastX-FFirstX+FLastY-FFirstY)/100.0 + 1.0;
00438
00439 FDeformationDone |= !areEqual(coef, 1.0);
00440
00441 setObjectScaleIsoCoef(coef);
00442 }
00443 else
00444 {
00445 float last3D[3];
00446 view->unproject(FLastX , FLastY , last3D);
00447
00448 CVertex R =
00449 CGeometry::orthoProjectVertexOnPlane(FParameterScale->getCenter(),
00450 view->getLookAt() +
00451 view->getEyeDirection(),
00452 view->getEyeDirection());
00453
00454 CVertex vect = CVertex(FFirst3D[0], FFirst3D[1], FFirst3D[2])-R;
00455
00456 for (int i=0;i<3;++i)
00457 if (!isZero(vect.getCoord(i)))
00458 vect.setCoord(i,1/vect.getCoord(i));
00459
00460 vect = (CVertex(last3D[0], last3D[1], last3D[2])-R).multiply(vect);
00461
00462 FDeformationDone |= ( vect != CVertex(1,1,1) );
00463
00464 setObjectScaleCoef(vect);
00465 }
00466 }
00467
00468 void CControlerGMap::modeTransformationOperationStop()
00469 {}
00470
00471 void CControlerGMap::addPonderationCoefs()
00472 {
00473 FDirectInfoPonderation = FMap->getNewDirectInfo();
00474 FMap->allocCoordToDirectInfo(getSelectionMark(),
00475 FDirectInfoPonderation,
00476 ORBIT_VERTEX);
00477 }
00478
00479 void CControlerGMap::delPonderationCoefs()
00480 {
00481 FMap->freeMemoryFromDirectInfo(getSelectionMark(),
00482 FDirectInfoPonderation,
00483 ORBIT_VERTEX);
00484 FMap->freeDirectInfo(FDirectInfoPonderation);
00485 FDirectInfoPonderation = -1;
00486 }
00487
00488 void CControlerGMap::updatePonderationCoefs()
00489 {
00490 CVertex center = FParameterPonderation->getPonderationCenter();
00491 CVertex vect = FParameterPonderation->getPonderationVector();
00492
00493 if (vect.isNull())
00494 vect = OZ;
00495
00496 switch (FParameterPonderation->getPonderationType())
00497 {
00498 case PONDERATION_POINT:
00499 FMap->computeDistanceToVertex(getSelectionMark(),
00500 FDirectInfoPonderation, center);
00501 break;
00502
00503 case PONDERATION_AXE:
00504 FMap->computeDistanceToLine(getSelectionMark(),
00505 FDirectInfoPonderation, center, vect);
00506 break;
00507
00508 case PONDERATION_PLANE:
00509 FMap->computeDistanceToPlane(getSelectionMark(),
00510 FDirectInfoPonderation, center, vect);
00511 break;
00512
00513 default:
00514 return;
00515 }
00516
00517 if (FParameterPonderation->getPonderationStretchIn())
00518 FMap->normalizeParameter(getSelectionMark(),
00519 FDirectInfoPonderation,
00520 FParameterPonderation->
00521 getPonderationStretchInMin(),
00522 FParameterPonderation->
00523 getPonderationStretchInMax());
00524
00525 FMap->applyFunctionOnParameter(getSelectionMark(),
00526 FDirectInfoPonderation,
00527 FParameterPonderation->
00528 getPonderationFunctionType());
00529
00530 if (FParameterPonderation->getPonderationStretchOut())
00531 FMap->normalizeParameter(getSelectionMark(),
00532 FDirectInfoPonderation,
00533 FParameterPonderation->
00534 getPonderationStretchOutMin(),
00535 FParameterPonderation->
00536 getPonderationStretchOutMax());
00537 }
00538