fGizmoC.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "fGizmoC.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma link "GLS.BaseClasses"
  8. #pragma link "GLS.BitmapFont"
  9. #pragma link "GLS.Cadencer"
  10. #pragma link "GLS.Coordinates"
  11. #pragma link "GLS.GeomObjects"
  12. #pragma link "GLS.Objects"
  13. #pragma link "GLS.Scene"
  14. #pragma link "GLS.SceneViewer"
  15. #pragma link "GLS.WindowsFont"
  16. #pragma link "GLS.VectorFileObjects"
  17. #pragma resource "*.dfm"
  18. TForm1 *Form1;
  19. //---------------------------------------------------------------------------
  20. __fastcall TForm1::TForm1(TComponent* Owner)
  21. : TForm(Owner)
  22. {
  23. }
  24. //---------------------------------------------------------------------------
  25. void __fastcall TForm1::GLCadencer1Progress(TObject *Sender, const double deltaTime,
  26. const double newTime)
  27. {
  28. Viewer->Invalidate();
  29. }
  30. //---------------------------------------------------------------------------
  31. void __fastcall TForm1::OptPickModeClick(TObject *Sender)
  32. {
  33. Gizmo->PickMode = (TGLGizmoPickMode)OptPickMode->ItemIndex;
  34. }
  35. //---------------------------------------------------------------------------
  36. void __fastcall TForm1::ViewerMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift,
  37. int X, int Y)
  38. {
  39. mx = X;
  40. my = Y;
  41. Gizmo->ViewerMouseDown(X, Y);
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TForm1::ViewerMouseMove(TObject *Sender, TShiftState Shift, int X,
  45. int Y)
  46. {
  47. //if noMouseMotion then exit;
  48. if (Shift.Contains(ssLeft) && (Gizmo->SelectedObj == NULL))
  49. Camera->MoveAroundTarget(Y - my, mx - X);
  50. else
  51. if (Shift.Contains(ssRight) && (Gizmo->SelectedObj == NULL))
  52. {
  53. if (my > Y)
  54. Camera->AdjustDistanceToTarget(1.05);
  55. else
  56. Camera->AdjustDistanceToTarget(0.95);
  57. Gizmo->MoveCoef = Camera->DistanceToTarget() / 1000;
  58. }
  59. else
  60. Gizmo->ViewerMouseMove(X, Y);
  61. mx = X;
  62. my = Y;
  63. }
  64. //---------------------------------------------------------------------------
  65. void __fastcall TForm1::ViewerMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift,
  66. int X, int Y)
  67. {
  68. Gizmo->ViewerMouseUp(X, Y);
  69. }
  70. //---------------------------------------------------------------------------
  71. // Recurse root object to fill list of pickable objects when using PickMode=pmRaycast
  72. void __fastcall TForm1::FillPickableObjectsList(TGLBaseSceneObject *root, bool doClearList)
  73. {
  74. int t;
  75. if (doClearList)
  76. Gizmo->PickableObjectsWithRayCast->Clear();
  77. for (t = 0; t < root->Count - 1; t++)
  78. {
  79. Gizmo->PickableObjectsWithRayCast->Add(&root[t]);
  80. // FillPickableObjectsList(&root[t], false); // raised exception with stack overflow
  81. }
  82. }
  83. //---------------------------------------------------------------------------
  84. void __fastcall TForm1::FormShow(TObject *Sender)
  85. {
  86. Viewer->SetFocus();
  87. Gizmo->RootGizmo = RootGizmo;
  88. // Fill list of pickable objects when using PickMode=pmRaycast
  89. FillPickableObjectsList(GLDummyCube1, true);
  90. }
  91. //---------------------------------------------------------------------------
  92. void __fastcall TForm1::edAutoZoomFactorKeyPress(TObject *Sender, System::WideChar &Key)
  93. {
  94. if (Key != ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', ','))
  95. Key = 0;
  96. }
  97. //---------------------------------------------------------------------------
  98. void __fastcall TForm1::CheckBox12Click(TObject *Sender)
  99. {
  100. bool Check;
  101. // (Sender as TCheckBox).Checked:=Not((Sender as TCheckBox).Checked);
  102. Check = CheckBox12->Checked;
  103. switch (CheckBox12->Tag)
  104. {
  105. case 0: Gizmo->Enabled = Check; break;
  106. case 1: Gizmo->ExcludeObjects = Check; break;
  107. case 2:
  108. {
  109. Gizmo->ForceAxis = Check;
  110. CBXAxis->Enabled = Check;
  111. break;
  112. };
  113. case 3:
  114. {
  115. Gizmo->ForceOperation = Check;
  116. CBXOperation->Enabled = Check;
  117. break;
  118. }
  119. case 4: Gizmo->ForceUniformScale = Check; break;
  120. case 5: if (Check)
  121. Gizmo->GizmoElements = Gizmo->GizmoElements << geAxisLabel;
  122. else
  123. Gizmo->GizmoElements = Gizmo->GizmoElements >> geAxisLabel;
  124. break;
  125. case 6:
  126. {
  127. if (Check)
  128. {
  129. Gizmo->GizmoElements = Gizmo->GizmoElements << geObjectInfos;
  130. CheckBox7->Enabled = Check;
  131. CheckBox8->Enabled = Check;
  132. CheckBox9->Enabled = Check;
  133. }
  134. else
  135. {
  136. Gizmo->GizmoElements = Gizmo->GizmoElements >> geObjectInfos;
  137. CheckBox7->Enabled = Check;
  138. CheckBox8->Enabled = Check;
  139. CheckBox9->Enabled = Check;
  140. }
  141. break;
  142. }
  143. case 7: Gizmo->NoZWrite = Check; break;
  144. case 8:
  145. {
  146. Gizmo->AutoZoom = Check;
  147. if (Check)
  148. {
  149. edAutoZoomFactor->Enabled = true;
  150. edZoomFactor->Enabled = false;
  151. }
  152. else
  153. {
  154. edAutoZoomFactor->Enabled = false;
  155. edZoomFactor->Enabled = true;
  156. }
  157. break;
  158. }
  159. case 9: if (Check)
  160. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels << vliName;
  161. else
  162. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels >> vliName;
  163. break;
  164. case 10: if (Check)
  165. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels << vliOperation;
  166. else
  167. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels >> vliOperation;
  168. break;
  169. case 11: if (Check)
  170. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels << vliCoords;
  171. else
  172. Gizmo->VisibleInfoLabels = Gizmo->VisibleInfoLabels >> vliCoords;
  173. break;
  174. case 12: if (Check)
  175. Gizmo->GizmoElements = Gizmo->GizmoElements << geMove;
  176. else
  177. Gizmo->GizmoElements = Gizmo->GizmoElements >> geMove;
  178. break;
  179. case 13: if (Check)
  180. Gizmo->GizmoElements = Gizmo->GizmoElements << geRotate;
  181. else
  182. Gizmo->GizmoElements = Gizmo->GizmoElements >> geRotate;
  183. break;
  184. case 14: if (Check)
  185. Gizmo->GizmoElements = Gizmo->GizmoElements << geScale;
  186. else
  187. Gizmo->GizmoElements = Gizmo->GizmoElements >> geScale;
  188. break;
  189. default:
  190. ;
  191. }
  192. }
  193. //---------------------------------------------------------------------------
  194. void __fastcall TForm1::CBXAxisChange(TObject *Sender)
  195. {
  196. switch (CBXAxis->ItemIndex)
  197. {
  198. case 0: Gizmo->SelAxis = gaNone; break;
  199. case 1: Gizmo->SelAxis = gaX; break;
  200. case 2: Gizmo->SelAxis = gaXY; break;
  201. case 3: Gizmo->SelAxis = gaXZ; break;
  202. case 4: Gizmo->SelAxis = gaY; break;
  203. case 5: Gizmo->SelAxis = gaYZ; break;
  204. case 6: Gizmo->SelAxis = gaZ; break;
  205. default: ;
  206. }
  207. }
  208. //---------------------------------------------------------------------------
  209. void __fastcall TForm1::CBXOperationChange(TObject *Sender)
  210. {
  211. switch (CBXOperation->ItemIndex)
  212. {
  213. case 0: Gizmo->Operation = gopNone; break;
  214. case 1: Gizmo->Operation = gopMove; break;
  215. case 2: Gizmo->Operation = gopRotate; break;
  216. case 3: Gizmo->Operation = gopScale; break;
  217. default:
  218. ;
  219. }
  220. }
  221. //---------------------------------------------------------------------------
  222. void __fastcall TForm1::edMoveCoefChange(TObject *Sender)
  223. {
  224. if (edMoveCoef->Text != "")
  225. Gizmo->MoveCoef = StrToFloatDef(edMoveCoef->Text);
  226. }
  227. //---------------------------------------------------------------------------
  228. void __fastcall TForm1::edRotateCoefChange(TObject *Sender)
  229. {
  230. if (edRotateCoef->Text != "")
  231. Gizmo->RotationCoef = StrToFloatDef(edRotateCoef->Text);
  232. }
  233. //---------------------------------------------------------------------------
  234. void __fastcall TForm1::edGizmoThicknessChange(TObject *Sender)
  235. {
  236. Gizmo->GizmoThickness = StrToFloatDef(edGizmoThickness->Text);
  237. }
  238. //---------------------------------------------------------------------------
  239. void __fastcall TForm1::edScaleCoefChange(TObject *Sender)
  240. {
  241. if (edScaleCoef->Text != "")
  242. Gizmo->ScaleCoef = StrToFloatDef(edScaleCoef->Text);
  243. }
  244. //---------------------------------------------------------------------------
  245. void __fastcall TForm1::edAutoZoomFactorChange(TObject *Sender)
  246. {
  247. if (edAutoZoomFactor->Text != "")
  248. Gizmo->AutoZoomFactor = StrToFloatDef(edAutoZoomFactor->Text);
  249. }
  250. //---------------------------------------------------------------------------
  251. void __fastcall TForm1::edZoomFactorChange(TObject *Sender)
  252. {
  253. if (edZoomFactor->Text != "")
  254. Gizmo->ZoomFactor = StrToFloatDef(edZoomFactor->Text);
  255. }
  256. //---------------------------------------------------------------------------
  257. void __fastcall TForm1::ColorBox1Change(TObject *Sender)
  258. {
  259. switch (ColorBox1->Tag)
  260. {
  261. case 0: {Gizmo->BoundingBoxColor->AsWinColor = ColorBox1->Selected; break;}
  262. case 1: {Gizmo->VisibleInfoLabelsColor->AsWinColor = ColorBox2->Selected; break;}
  263. case 2: {Gizmo->SelectedColor->AsWinColor = ColorBox3->Selected; break;}
  264. default:
  265. ;
  266. }
  267. }
  268. //---------------------------------------------------------------------------
  269. void __fastcall TForm1::FormCreate(TObject *Sender)
  270. {
  271. Gizmo = new TGLGizmo(this);
  272. Gizmo->LabelFont = WindowsBitmapFont;
  273. Gizmo->Viewer = Viewer;
  274. }
  275. //---------------------------------------------------------------------------
  276. void __fastcall TForm1::FormDestroy(TObject *Sender)
  277. {
  278. Gizmo->Free();
  279. }
  280. //---------------------------------------------------------------------------