source: trunk/source/visualization/management/src/G4VisCommandsViewerSet.cc@ 953

Last change on this file since 953 was 952, checked in by garnier, 17 years ago

en test

  • Property svn:mime-type set to text/cpp
File size: 36.4 KB
Line 
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id: G4VisCommandsViewerSet.cc,v 1.49 2007/07/10 17:51:54 allison Exp $
28// GEANT4 tag $Name: geant4-09-02-ref-03 $
29
30// /vis/viewer/set commands - John Allison 16th May 2000
31
32#include "G4VisCommandsViewerSet.hh"
33
34#include "G4UIcommand.hh"
35#include "G4UIcmdWithAString.hh"
36#include "G4UIcmdWithABool.hh"
37#include "G4UIcmdWithAnInteger.hh"
38#include "G4UIcmdWithADouble.hh"
39#include "G4UnitsTable.hh"
40#include "G4VisManager.hh"
41#include "G4Polyhedron.hh"
42
43#include <sstream>
44#include <cctype>
45
46G4VisCommandsViewerSet::G4VisCommandsViewerSet ():
47 fLightsVector (G4ThreeVector(1.,1.,1.)),
48 fUpVector (G4ThreeVector(0.,1.,0.)),
49 fViewpointVector (G4ThreeVector(0.,0.,1.))
50{
51 G4bool omitable;
52 G4UIparameter* parameter;
53
54 fpCommandAll = new G4UIcmdWithAString ("/vis/viewer/set/all",this);
55 fpCommandAll->SetGuidance
56 ("Copies view parameters.");
57 fpCommandAll->SetGuidance
58 ("Copies view parameters (except the autoRefresh status) from"
59 "\nfrom-viewer to current viewer.");
60 fpCommandAll->SetParameterName ("from-viewer-name",omitable = false);
61
62 fpCommandAutoRefresh = new G4UIcmdWithABool
63 ("/vis/viewer/set/autoRefresh",this);
64 fpCommandAutoRefresh->SetGuidance("Sets auto-refresh.");
65 fpCommandAutoRefresh->SetGuidance
66 ("If true, view is automatically refreshed after a change of"
67 "\nview parameters.");
68 fpCommandAutoRefresh->SetParameterName("auto-refresh",omitable = true);
69 fpCommandAutoRefresh->SetDefaultValue(true);
70
71 fpCommandAuxEdge = new G4UIcmdWithABool
72 ("/vis/viewer/set/auxiliaryEdge",this);
73 fpCommandAuxEdge->SetGuidance("Sets visibility of auxiliary edges");
74 fpCommandAuxEdge->SetGuidance
75 ("Auxiliary edges, i.e., those that are part of a curved surface,"
76 "\nsometimes called soft edges, become visible/invisible.");
77 fpCommandAuxEdge->SetParameterName("edge",omitable = true);
78 fpCommandAuxEdge->SetDefaultValue(true);
79
80 fpCommandBackground = new G4UIcommand
81 ("/vis/viewer/set/background",this);
82 fpCommandBackground->SetGuidance
83 ("Set background colour and transparency (default black and opaque).");
84 fpCommandBackground->SetGuidance
85 ("Accepts (a) RGB triplet. e.g., \".3 .4 .5\", or"
86 "\n(b) string such as \"white\", \"black\", \"grey\", \"red\"..."
87 "\n(c) an additional number for opacity, e.g., \".3 .4 .5 .6\""
88 "\n or \"grey ! ! .6\" (note \"!\"'s for unused green and blue parameters),"
89 "\n e.g. \"! ! ! 0.\" for a transparent background.");
90 parameter = new G4UIparameter("red_or_string", 's', omitable = true);
91 parameter -> SetDefaultValue ("0.");
92 fpCommandBackground -> SetParameter (parameter);
93 parameter = new G4UIparameter("green", 'd', omitable = true);
94 parameter -> SetDefaultValue (0.);
95 fpCommandBackground -> SetParameter (parameter);
96 parameter = new G4UIparameter ("blue", 'd', omitable = true);
97 parameter -> SetDefaultValue (0.);
98 fpCommandBackground -> SetParameter (parameter);
99 parameter = new G4UIparameter ("opacity", 'd', omitable = true);
100 parameter -> SetDefaultValue (1.);
101 fpCommandBackground -> SetParameter (parameter);
102
103 fpCommandCulling = new G4UIcommand("/vis/viewer/set/culling",this);
104 fpCommandCulling->SetGuidance ("Set culling options.");
105 fpCommandCulling->SetGuidance
106 ("\"global\": enables/disables all other culling options.");
107 fpCommandCulling->SetGuidance
108 ("\"coveredDaughters\": culls, i.e., eliminates, volumes that would not"
109 "\nbe seen because covered by ancester volumes in surface drawing mode,"
110 "\nand then only if the ancesters are visible and opaque, and then only"
111 "\nif no sections or cutaways are in operation. Intended solely to"
112 "\nimprove the speed of rendering visible volumes.");
113 fpCommandCulling->SetGuidance
114 ("\"invisible\": culls objects with the invisible attribute set.");
115 fpCommandCulling->SetGuidance
116 ("\"density\": culls volumes with density lower than threshold. Useful"
117 "\nfor eliminating \"container volumes\" with no physical correspondence,"
118 "\nwhose material is usually air. If this is selected, provide threshold"
119 "\ndensity and unit (g/cm3 mg/cm3 or kg/m3)."
120 );
121 parameter = new G4UIparameter("culling-option",'s',omitable = false);
122 parameter->SetParameterCandidates
123 ("global coveredDaughters invisible density");
124 fpCommandCulling->SetParameter(parameter);
125 parameter = new G4UIparameter("action",'b',omitable = true);
126 parameter->SetDefaultValue(1);
127 fpCommandCulling->SetParameter(parameter);
128 parameter = new G4UIparameter("density-threshold",'d',omitable = true);
129 parameter->SetDefaultValue("0.01");
130 fpCommandCulling->SetParameter(parameter);
131 parameter = new G4UIparameter("unit",'s',omitable = true);
132 parameter->SetParameterCandidates ("g/cm3, mg/cm3 kg/m3");
133 parameter->SetDefaultValue("g/cm3");
134 fpCommandCulling->SetParameter(parameter);
135
136 fpCommandCutawayMode =
137 new G4UIcmdWithAString ("/vis/viewer/set/cutawayMode", this);
138 fpCommandCutawayMode->SetGuidance
139 ("Sets cutaway mode - add (union) or multiply (intersection).");
140 fpCommandCutawayMode->SetParameterName ("cutaway-mode",omitable = false);
141 fpCommandCutawayMode->SetCandidates ("add union multiply intersection");
142 fpCommandCutawayMode->SetDefaultValue("union");
143
144 fpCommandEdge = new G4UIcmdWithABool("/vis/viewer/set/edge",this);
145 fpCommandEdge->SetGuidance
146 ("Edges become visible/invisible in surface mode.");
147 fpCommandEdge->SetParameterName("edge",omitable = true);
148 fpCommandEdge->SetDefaultValue(true);
149
150 fpCommandExplodeFactor = new G4UIcommand
151 ("/vis/viewer/set/explodeFactor", this);
152 fpCommandExplodeFactor->SetGuidance
153 ("Moves top-level drawn volumes by this factor from this centre.");
154 parameter = new G4UIparameter("explodeFactor", 'd', omitable=true);
155 parameter->SetParameterRange("explodeFactor>=1.");
156 parameter->SetDefaultValue(1.);
157 fpCommandExplodeFactor->SetParameter(parameter);
158 parameter = new G4UIparameter("x",'d',omitable = true);
159 parameter->SetDefaultValue (0);
160 parameter->SetGuidance ("Coordinate of explode centre.");
161 fpCommandExplodeFactor->SetParameter(parameter);
162 parameter = new G4UIparameter("y",'d',omitable = true);
163 parameter->SetDefaultValue (0);
164 parameter->SetGuidance ("Coordinate of explode centre.");
165 fpCommandExplodeFactor->SetParameter(parameter);
166 parameter = new G4UIparameter("z",'d',omitable = true);
167 parameter->SetDefaultValue (0);
168 parameter->SetGuidance ("Coordinate of explode centre.");
169 fpCommandExplodeFactor->SetParameter(parameter);
170 parameter = new G4UIparameter("unit",'s',omitable = true);
171 parameter->SetDefaultValue ("m");
172 parameter->SetGuidance ("Unit of explode centre.");
173 fpCommandExplodeFactor->SetParameter(parameter);
174
175 fpCommandGlobalLineWidthScale = new G4UIcmdWithADouble
176 ("/vis/viewer/set/globalLineWidthScale", this);
177 fpCommandGlobalLineWidthScale->SetGuidance
178 ("Multiplies line widths by this factor.");
179 fpCommandGlobalLineWidthScale->
180 SetParameterName("scale-factor", omitable=true);
181 fpCommandGlobalLineWidthScale->SetDefaultValue(1.);
182
183 fpCommandGlobalMarkerScale = new G4UIcmdWithADouble
184 ("/vis/viewer/set/globalMarkerScale", this);
185 fpCommandGlobalMarkerScale->SetGuidance
186 ("Multiplies marker sizes by this factor.");
187 fpCommandGlobalMarkerScale->
188 SetParameterName("scale-factor", omitable=true);
189 fpCommandGlobalMarkerScale->SetDefaultValue(1.);
190
191 fpCommandHiddenEdge =
192 new G4UIcmdWithABool("/vis/viewer/set/hiddenEdge",this);
193 fpCommandHiddenEdge->SetGuidance
194 ("Edges become hidden/seen in wireframe or surface mode.");
195 fpCommandHiddenEdge->SetParameterName("hidden-edge",omitable = true);
196 fpCommandHiddenEdge->SetDefaultValue(true);
197
198 fpCommandHiddenMarker =
199 new G4UIcmdWithABool("/vis/viewer/set/hiddenMarker",this);
200 fpCommandHiddenMarker->SetGuidance
201 ("If true, closer objects hide markers. Otherwise, markers always show.");
202 fpCommandHiddenMarker->SetParameterName("hidden-marker",omitable = true);
203 fpCommandHiddenMarker->SetDefaultValue(true);
204
205 fpCommandLightsMove = new G4UIcmdWithAString
206 ("/vis/viewer/set/lightsMove",this);
207 fpCommandLightsMove->SetGuidance
208 ("Lights move with camera or with object");
209 fpCommandLightsMove->SetParameterName("lightsMove",omitable = false);
210 fpCommandLightsMove->SetCandidates
211 ("cam camera with-camera obj object with-object");
212
213 fpCommandLightsThetaPhi = new G4UIcommand
214 ("/vis/viewer/set/lightsThetaPhi", this);
215 fpCommandLightsThetaPhi->SetGuidance
216 ("Set direction from target to lights.");
217 parameter = new G4UIparameter("theta", 'd', omitable = true);
218 parameter -> SetDefaultValue(60.);
219 fpCommandLightsThetaPhi -> SetParameter (parameter);
220 parameter = new G4UIparameter("phi", 'd', omitable = true);
221 parameter -> SetDefaultValue(45.);
222 fpCommandLightsThetaPhi -> SetParameter (parameter);
223 parameter = new G4UIparameter ("unit", 's', omitable = true);
224 parameter -> SetDefaultValue ("deg");
225 fpCommandLightsThetaPhi -> SetParameter (parameter);
226
227 fpCommandLightsVector = new G4UIcommand
228 ("/vis/viewer/set/lightsVector", this);
229 fpCommandLightsVector->SetGuidance
230 ("Set direction from target to lights.");
231 parameter = new G4UIparameter("x", 'd', omitable = true);
232 parameter -> SetDefaultValue (1);
233 fpCommandLightsVector -> SetParameter (parameter);
234 parameter = new G4UIparameter("y", 'd', omitable = true);
235 parameter -> SetDefaultValue (1);
236 fpCommandLightsVector -> SetParameter (parameter);
237 parameter = new G4UIparameter ("z", 'd', omitable = true);
238 parameter -> SetDefaultValue (1);
239 fpCommandLightsVector -> SetParameter (parameter);
240
241 fpCommandLineSegments = new G4UIcmdWithAnInteger
242 ("/vis/viewer/set/lineSegmentsPerCircle",this);
243 fpCommandLineSegments->SetGuidance
244 ("Set number of sides per circle for polygon/polyhedron drawing.");
245 fpCommandLineSegments->SetGuidance
246 ("Refers to graphical representation of objects with curved lines/surfaces.");
247 fpCommandLineSegments->SetParameterName("line-segments",omitable = true);
248 fpCommandLineSegments->SetDefaultValue(24);
249
250 fpCommandPicking = new G4UIcmdWithABool
251 ("/vis/viewer/set/picking",this);
252 fpCommandPicking->SetGuidance("Sets picking, if available.");
253 fpCommandPicking->SetGuidance
254 ("If true, view is set up for picking, if available."
255 "\nFor required actions, watch for instructions for viewer.");
256 fpCommandPicking->SetParameterName("picking",omitable = true);
257 fpCommandPicking->SetDefaultValue(true);
258
259 fpCommandProjection = new G4UIcommand("/vis/viewer/set/projection",this);
260 fpCommandProjection->SetGuidance
261 ("Orthogonal or perspective projection.");
262 parameter = new G4UIparameter("projection",'s',omitable = true);
263 parameter->SetParameterCandidates("o orthogonal p perspective");
264 parameter->SetDefaultValue("orthogonal");
265 fpCommandProjection->SetParameter(parameter);
266 parameter = new G4UIparameter("field-half-angle",'d',omitable = true);
267 parameter->SetDefaultValue(30.);
268 fpCommandProjection->SetParameter(parameter);
269 parameter = new G4UIparameter("unit",'s',omitable = true);
270 parameter->SetDefaultValue("deg");
271 fpCommandProjection->SetParameter(parameter);
272
273 fpCommandSectionPlane = new G4UIcommand("/vis/viewer/set/sectionPlane",this);
274 fpCommandSectionPlane -> SetGuidance
275 ("Set plane for drawing section (DCUT).");
276 fpCommandSectionPlane -> SetGuidance
277 ("E.g., for a y-z plane at x = 1 cm:"
278 "\n\"/vis/viewer/set/sectionPlane on 1 0 0 cm 1 0 0\"."
279 "\nTo turn off: /vis/viewer/set/sectionPlane off");
280 parameter = new G4UIparameter("Selector",'c',true);
281 parameter -> SetDefaultValue ("on");
282 fpCommandSectionPlane->SetParameter(parameter);
283 parameter = new G4UIparameter("x",'d',omitable = true);
284 parameter -> SetDefaultValue (0);
285 parameter -> SetGuidance ("Coordinate of point on the plane.");
286 fpCommandSectionPlane->SetParameter(parameter);
287 parameter = new G4UIparameter("y",'d',omitable = true);
288 parameter -> SetDefaultValue (0);
289 parameter -> SetGuidance ("Coordinate of point on the plane.");
290 fpCommandSectionPlane->SetParameter(parameter);
291 parameter = new G4UIparameter("z",'d',omitable = true);
292 parameter -> SetDefaultValue (0);
293 parameter -> SetGuidance ("Coordinate of point on the plane.");
294 fpCommandSectionPlane->SetParameter(parameter);
295 parameter = new G4UIparameter("unit",'s',omitable = true);
296 parameter -> SetDefaultValue ("m");
297 parameter -> SetGuidance ("Unit of point on the plane.");
298 fpCommandSectionPlane->SetParameter(parameter);
299 parameter = new G4UIparameter("nx",'d',omitable = true);
300 parameter -> SetDefaultValue (1);
301 parameter -> SetGuidance ("Component of plane normal.");
302 fpCommandSectionPlane->SetParameter(parameter);
303 parameter = new G4UIparameter("ny",'d',omitable = true);
304 parameter -> SetDefaultValue (0);
305 parameter -> SetGuidance ("Component of plane normal.");
306 fpCommandSectionPlane->SetParameter(parameter);
307 parameter = new G4UIparameter("nz",'d',omitable = true);
308 parameter -> SetDefaultValue (0);
309 parameter -> SetGuidance ("Component of plane normal.");
310 fpCommandSectionPlane->SetParameter(parameter);
311
312 fpCommandStyle = new G4UIcmdWithAString ("/vis/viewer/set/style",this);
313 fpCommandStyle->SetGuidance
314 ("Set style of drawing - w[ireframe] or s[urface].");
315 fpCommandStyle->SetGuidance
316 ("(Hidden line drawing is controlled by \"/vis/viewer/set/hiddenEdge\".)");
317 fpCommandStyle->SetParameterName ("style",omitable = false);
318
319 fpCommandUpThetaPhi = new G4UIcommand
320 ("/vis/viewer/set/upThetaPhi", this);
321 fpCommandUpThetaPhi -> SetGuidance ("Set up vector.");
322 fpCommandUpThetaPhi -> SetGuidance
323 ("Viewer will attempt always to show this direction upwards.");
324 parameter = new G4UIparameter("theta", 'd', omitable = true);
325 parameter -> SetDefaultValue (90.);
326 fpCommandUpThetaPhi -> SetParameter (parameter);
327 parameter = new G4UIparameter("phi", 'd', omitable = true);
328 parameter -> SetDefaultValue (90.);
329 fpCommandUpThetaPhi -> SetParameter (parameter);
330 parameter = new G4UIparameter ("unit", 's', omitable = true);
331 parameter -> SetDefaultValue ("deg");
332 fpCommandUpThetaPhi -> SetParameter (parameter);
333
334 fpCommandUpVector = new G4UIcommand
335 ("/vis/viewer/set/upVector", this);
336 fpCommandUpVector -> SetGuidance ("Set up vector.");
337 fpCommandUpVector -> SetGuidance
338 ("Viewer will attempt always to show this direction upwards.");
339 parameter = new G4UIparameter("x", 'd', omitable = true);
340 parameter -> SetDefaultValue (0.);
341 fpCommandUpVector -> SetParameter (parameter);
342 parameter = new G4UIparameter("y", 'd', omitable = true);
343 parameter -> SetDefaultValue (1.);
344 fpCommandUpVector -> SetParameter (parameter);
345 parameter = new G4UIparameter ("z", 'd', omitable = true);
346 parameter -> SetDefaultValue (0.);
347 fpCommandUpVector -> SetParameter (parameter);
348
349 fpCommandViewpointThetaPhi = new G4UIcommand
350 ("/vis/viewer/set/viewpointThetaPhi", this);
351 fpCommandViewpointThetaPhi -> SetGuidance
352 ("Set direction from target to camera.");
353 fpCommandViewpointThetaPhi -> SetGuidance
354 ("Also changes lightpoint direction if lights are set to move with camera.");
355 parameter = new G4UIparameter("theta", 'd', omitable = true);
356 parameter -> SetDefaultValue (60.);
357 fpCommandViewpointThetaPhi -> SetParameter (parameter);
358 parameter = new G4UIparameter("phi", 'd', omitable = true);
359 parameter -> SetDefaultValue (45.);
360 fpCommandViewpointThetaPhi -> SetParameter (parameter);
361 parameter = new G4UIparameter ("unit", 's', omitable = true);
362 parameter -> SetDefaultValue ("deg");
363 fpCommandViewpointThetaPhi -> SetParameter (parameter);
364
365 fpCommandViewpointVector = new G4UIcommand
366 ("/vis/viewer/set/viewpointVector", this);
367 fpCommandViewpointVector -> SetGuidance
368 ("Set direction from target to camera.");
369 fpCommandViewpointVector -> SetGuidance
370 ("Also changes lightpoint direction if lights are set to move with camera.");
371 parameter = new G4UIparameter("x", 'd', omitable = true);
372 parameter -> SetDefaultValue (1.);
373 fpCommandViewpointVector -> SetParameter (parameter);
374 parameter = new G4UIparameter("y", 'd', omitable = true);
375 parameter -> SetDefaultValue (1.);
376 fpCommandViewpointVector -> SetParameter (parameter);
377 parameter = new G4UIparameter ("z", 'd', omitable = true);
378 parameter -> SetDefaultValue (1.);
379 fpCommandViewpointVector -> SetParameter (parameter);
380}
381
382G4VisCommandsViewerSet::~G4VisCommandsViewerSet() {
383 delete fpCommandAll;
384 delete fpCommandAuxEdge;
385 delete fpCommandAutoRefresh;
386 delete fpCommandBackground;
387 delete fpCommandCulling;
388 delete fpCommandCutawayMode;
389 delete fpCommandEdge;
390 delete fpCommandExplodeFactor;
391 delete fpCommandGlobalLineWidthScale;
392 delete fpCommandGlobalMarkerScale;
393 delete fpCommandHiddenEdge;
394 delete fpCommandHiddenMarker;
395 delete fpCommandLineSegments;
396 delete fpCommandLightsMove;
397 delete fpCommandLightsThetaPhi;
398 delete fpCommandLightsVector;
399 delete fpCommandPicking;
400 delete fpCommandProjection;
401 delete fpCommandSectionPlane;
402 delete fpCommandStyle;
403 delete fpCommandUpThetaPhi;
404 delete fpCommandUpVector;
405 delete fpCommandViewpointThetaPhi;
406 delete fpCommandViewpointVector;
407}
408
409G4String G4VisCommandsViewerSet::GetCurrentValue(G4UIcommand*) {
410 return "";
411}
412
413void G4VisCommandsViewerSet::SetNewValue
414(G4UIcommand* command,G4String newValue) {
415
416 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
417
418 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
419 if (!currentViewer) {
420 if (verbosity >= G4VisManager::errors) {
421 G4cout <<
422 "ERROR: G4VisCommandsViewerSet::SetNewValue: no current viewer."
423 << G4endl;
424 }
425 return;
426 }
427
428 G4ViewParameters vp = currentViewer->GetViewParameters();
429
430 if (command == fpCommandAll) {
431 G4VViewer* fromViewer = fpVisManager->GetViewer(newValue);
432 if (!fromViewer) {
433 if (verbosity >= G4VisManager::errors) {
434 G4cout <<
435 "ERROR: G4VisCommandsViewerSet::SetNewValue: all:"
436 "\n unrecognised from-viewer."
437 << G4endl;
438 }
439 return;
440 }
441 if (fromViewer == currentViewer) {
442 if (verbosity >= G4VisManager::warnings) {
443 G4cout <<
444 "WARNING: G4VisCommandsViewerSet::SetNewValue: all:"
445 "\n from-viewer and current viewer are identical."
446 << G4endl;
447 }
448 return;
449 }
450 // Copy view parameters except for autoRefresh...
451 G4bool currentAutoRefresh =
452 currentViewer->GetViewParameters().IsAutoRefresh();
453 vp = fromViewer->GetViewParameters();
454 vp.SetAutoRefresh(currentAutoRefresh);
455 if (verbosity >= G4VisManager::confirmations) {
456 G4cout << "View parameters of viewer \"" << currentViewer->GetName()
457 << "\"\n set to those of viewer \"" << fromViewer->GetName()
458 << "\"."
459 << G4endl;
460 }
461 }
462
463 else if (command == fpCommandAutoRefresh) {
464 G4bool autoRefresh = G4UIcommand::ConvertToBool(newValue);
465 vp.SetAutoRefresh(autoRefresh);
466 if (verbosity >= G4VisManager::confirmations) {
467 G4cout << "Views will ";
468 if (!vp.IsAutoRefresh()) G4cout << "not ";
469 G4cout << "be automatically refreshed after a change of view parameters."
470 << G4endl;
471 }
472 if (!vp.IsAutoRefresh()) {
473 currentViewer->SetViewParameters(vp);
474 return; // Avoid a refresh id auto-refresh has been set to off...
475 } // ...otherwise take normal action.
476 }
477
478 else if (command == fpCommandAuxEdge) {
479 vp.SetAuxEdgeVisible(G4UIcommand::ConvertToBool(newValue));
480 if (verbosity >= G4VisManager::confirmations) {
481 G4cout << "Auxiliary edges will ";
482 if (!vp.IsAuxEdgeVisible()) G4cout << "not ";
483 G4cout << "be visible." << G4endl;
484 }
485 }
486
487 else if (command == fpCommandBackground) {
488 G4String redOrString;
489 G4double green, blue, opacity;
490 std::istringstream iss(newValue);
491 iss >> redOrString >> green >> blue >> opacity;
492 G4Colour colour(0.,0.,0.); // Default black and opaque.
493 const size_t iPos0 = 0;
494 if (std::isalpha(redOrString[iPos0])) {
495 G4Colour::GetColour(redOrString, colour); // Remains default (black) if
496 // not found.
497 } else {
498 colour = G4Colour(G4UIcommand::ConvertTo3Vector(newValue));
499 }
500 colour = G4Colour(colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity);
501 vp.SetBackgroundColour(colour);
502 if (verbosity >= G4VisManager::confirmations) {
503 G4cout << "Background colour "
504 << vp.GetBackgroundColour()
505 << " requested."
506 << G4endl;
507 }
508 }
509
510 else if (command == fpCommandCulling) {
511 G4String cullingOption, stringFlag, unit;
512 G4double density;
513 std::istringstream is (newValue);
514 is >> cullingOption >> stringFlag >> density >> unit;
515 G4bool boolFlag = G4UIcommand::ConvertToBool(stringFlag);
516 if (cullingOption == "global") {
517 vp.SetCulling(boolFlag);
518 if (verbosity >= G4VisManager::confirmations) {
519 G4cout <<
520 "G4VisCommandsViewerSet::SetNewValue: culling: global culling flag"
521 " set to " << G4UIcommand::ConvertToString(boolFlag) <<
522 ".\n Does not change specific culling flags."
523 << G4endl;
524 }
525 }
526 else if (cullingOption == "coveredDaughters") {
527 vp.SetCullingCovered(boolFlag);
528 if (verbosity >= G4VisManager::confirmations) {
529 G4cout <<
530 "G4VisCommandsViewerSet::SetNewValue: culling: culling covered"
531 "\n daughters flag set to "
532 << G4UIcommand::ConvertToString(boolFlag) <<
533 ". Daughters covered by opaque mothers"
534 "\n will be culled, i.e., not drawn, if this flag is true."
535 "\n Note: this is only effective in surface drawing style,"
536 "\n and then only if the volumes are visible and opaque, and then"
537 "\n only if no sections or cutaways are in operation."
538 << G4endl;
539 }
540 }
541 else if (cullingOption == "invisible") {
542 vp.SetCullingInvisible(boolFlag);
543 if (verbosity >= G4VisManager::confirmations) {
544 G4cout <<
545 "G4VisCommandsViewerSet::SetNewValue: culling: culling invisible"
546 "\n flag set to "
547 << boolFlag << G4UIcommand::ConvertToString(boolFlag) <<
548 ". Volumes marked invisible will be culled,"
549 "\n i.e., not drawn, if this flag is true."
550 << G4endl;
551 }
552 }
553 else if (cullingOption == "density") {
554 vp.SetDensityCulling(boolFlag);
555 if (boolFlag) {
556 density *= G4UnitDefinition::GetValueOf(unit);
557 vp.SetVisibleDensity(density);
558 }
559 else {
560 density = vp.GetVisibleDensity();
561 }
562 if (verbosity >= G4VisManager::confirmations) {
563 G4cout <<
564 "G4VisCommandsViewerSet::SetNewValue: culling: culling by density"
565 "\n flag set to " << G4UIcommand::ConvertToString(boolFlag) <<
566 ". Volumes with density less than " <<
567 G4BestUnit(density,"Volumic Mass") <<
568 "\n will be culled, i.e., not drawn, if this flag is true."
569 << G4endl;
570 }
571 }
572 else {
573 if (verbosity >= G4VisManager::errors) {
574 G4cout <<
575 "ERROR: G4VisCommandsViewerSet::SetNewValue: culling:"
576 "\n option not recognised."
577 << G4endl;
578 }
579 }
580 }
581
582 else if (command == fpCommandCutawayMode) {
583 if (newValue == "add" || newValue == "union")
584 vp.SetCutawayMode(G4ViewParameters::cutawayUnion);
585 if (newValue == "multiply" || newValue == "intersection")
586 vp.SetCutawayMode(G4ViewParameters::cutawayIntersection);
587
588 if (verbosity >= G4VisManager::confirmations) {
589 G4cout << "Cutaway mode set to ";
590 if (vp.GetCutawayMode() == G4ViewParameters::cutawayUnion)
591 G4cout << "cutawayUnion";
592 if (vp.GetCutawayMode() == G4ViewParameters::cutawayIntersection)
593 G4cout << "cutawayIntersection";
594 G4cout << G4endl;
595 }
596 }
597
598 else if (command == fpCommandEdge) {
599 G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
600 if (G4UIcommand::ConvertToBool(newValue)) {
601 switch (existingStyle) {
602 case G4ViewParameters::wireframe:
603 break;
604 case G4ViewParameters::hlr:
605 break;
606 case G4ViewParameters::hsr:
607 vp.SetDrawingStyle(G4ViewParameters::hlhsr);
608 break;
609 case G4ViewParameters::hlhsr:
610 break;
611 }
612 }
613 else {
614 switch (existingStyle) {
615 case G4ViewParameters::wireframe:
616 break;
617 case G4ViewParameters::hlr:
618 break;
619 case G4ViewParameters::hsr:
620 break;
621 case G4ViewParameters::hlhsr:
622 vp.SetDrawingStyle(G4ViewParameters::hsr);
623 break;
624 }
625 }
626 if (verbosity >= G4VisManager::confirmations) {
627 G4cout << "Drawing style of viewer \"" << currentViewer->GetName()
628 << "\" set to " << vp.GetDrawingStyle()
629 << G4endl;
630 }
631 }
632
633 else if (command == fpCommandExplodeFactor) {
634 G4double explodeFactor, x, y, z;
635 G4String unitString;
636 std::istringstream is (newValue);
637 is >> explodeFactor >> x >> y >> z >> unitString;
638 G4double unit = G4UIcommand::ValueOf(unitString);
639 vp.SetExplodeFactor(explodeFactor);
640 vp.SetExplodeCentre(G4Point3D(x * unit, y * unit, z * unit));
641 if (verbosity >= G4VisManager::confirmations) {
642 G4cout << "Explode factor changed to " << vp.GetExplodeFactor()
643 << " from centre " << vp.GetExplodeCentre()
644 << G4endl;
645 }
646 }
647
648 else if (command == fpCommandGlobalLineWidthScale) {
649 G4double globalLineWidthScale
650 = fpCommandGlobalLineWidthScale->GetNewDoubleValue(newValue);
651 vp.SetGlobalLineWidthScale(globalLineWidthScale);
652 if (verbosity >= G4VisManager::confirmations) {
653 G4cout << "Global Line Width Scale changed to "
654 << vp.GetGlobalLineWidthScale() << G4endl;
655 }
656 }
657
658 else if (command == fpCommandGlobalMarkerScale) {
659 G4double globalMarkerScale
660 = fpCommandGlobalMarkerScale->GetNewDoubleValue(newValue);
661 vp.SetGlobalMarkerScale(globalMarkerScale);
662 if (verbosity >= G4VisManager::confirmations) {
663 G4cout << "Global Marker Scale changed to "
664 << vp.GetGlobalMarkerScale() << G4endl;
665 }
666 }
667
668 else if (command == fpCommandHiddenEdge) {
669 G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
670 if (G4UIcommand::ConvertToBool(newValue)) {
671 switch (existingStyle) {
672 case G4ViewParameters::wireframe:
673 vp.SetDrawingStyle(G4ViewParameters::hlr);
674 break;
675 case G4ViewParameters::hlr:
676 break;
677 case G4ViewParameters::hsr:
678 vp.SetDrawingStyle(G4ViewParameters::hlhsr);
679 break;
680 case G4ViewParameters::hlhsr:
681 break;
682 }
683 }
684 else {
685 switch (existingStyle) {
686 case G4ViewParameters::wireframe:
687 break;
688 case G4ViewParameters::hlr:
689 vp.SetDrawingStyle(G4ViewParameters::wireframe);
690 break;
691 case G4ViewParameters::hsr:
692 break;
693 case G4ViewParameters::hlhsr:
694 vp.SetDrawingStyle(G4ViewParameters::hsr);
695 break;
696 }
697 }
698 if (verbosity >= G4VisManager::confirmations) {
699 G4cout << "Drawing style of viewer \"" << currentViewer->GetName()
700 << "\" set to " << vp.GetDrawingStyle()
701 << G4endl;
702 }
703 }
704
705 else if (command == fpCommandHiddenMarker) {
706 G4bool hidden = G4UIcommand::ConvertToBool(newValue);
707 if (hidden) vp.SetMarkerHidden();
708 else vp.SetMarkerNotHidden();
709 if (verbosity >= G4VisManager::confirmations) {
710 G4cout << "Markers will ";
711 if (vp.IsMarkerNotHidden()) G4cout << "not ";
712 G4cout << "be hidden under solid objects." << G4endl;
713 }
714 }
715
716 else if (command == fpCommandLightsMove) {
717 G4String s (newValue);
718 if (s.find("cam") != G4String::npos) vp.SetLightsMoveWithCamera(true);
719 else if(s.find("obj") != G4String::npos) vp.SetLightsMoveWithCamera(false);
720 else {
721 if (verbosity >= G4VisManager::errors) {
722 G4cout << "ERROR: \"" << newValue << "\" not recognised."
723 " Looking for \"cam\" or \"obj\" in string." << G4endl;
724 }
725 }
726 if (verbosity >= G4VisManager::confirmations) {
727 G4cout << "Lights move with ";
728 if (vp.GetLightsMoveWithCamera())
729 G4cout << "camera (object appears to rotate).";
730 else G4cout << "object (the viewer appears to be moving).";
731 G4cout << G4endl;
732 }
733 }
734
735 else if (command == fpCommandLightsThetaPhi) {
736 G4double theta, phi;
737 ConvertToDoublePair(newValue, theta, phi);
738 G4double x = std::sin (theta) * std::cos (phi);
739 G4double y = std::sin (theta) * std::sin (phi);
740 G4double z = std::cos (theta);
741 fLightsVector = G4ThreeVector (x, y, z);
742 vp.SetLightpointDirection(fLightsVector);
743 if (verbosity >= G4VisManager::confirmations) {
744 G4cout << "Lights direction set to "
745 << vp.GetLightpointDirection() << G4endl;
746 }
747 }
748
749 else if (command == fpCommandLightsVector) {
750 fLightsVector = G4UIcommand::ConvertTo3Vector(newValue);
751 vp.SetLightpointDirection(fLightsVector);
752 if (verbosity >= G4VisManager::confirmations) {
753 G4cout << "Lights direction set to "
754 << vp.GetLightpointDirection() << G4endl;
755 }
756 }
757
758 else if (command == fpCommandLineSegments) {
759 G4int nSides = G4UIcommand::ConvertToInt(newValue);
760 nSides = vp.SetNoOfSides(nSides);
761 if (verbosity >= G4VisManager::confirmations) {
762 G4cout <<
763 "Number of line segements per circle in polygon approximation is "
764 << nSides << G4endl;
765 }
766 }
767
768 else if (command == fpCommandPicking) {
769 vp.SetPicking(G4UIcommand::ConvertToBool(newValue));
770 if (verbosity >= G4VisManager::confirmations) {
771 G4cout << "Picking ";
772 if (vp.IsPicking()) G4cout << "requested.";
773 else G4cout << "inhibited.";
774 G4cout << G4endl;
775 }
776 }
777
778 else if (command == fpCommandProjection) {
779 G4double fieldHalfAngle;
780 const size_t iPos0 = 0;
781 if (newValue[iPos0] == 'o') { // "orthogonal"
782 fieldHalfAngle = 0.;
783 }
784 else if (newValue[iPos0] == 'p') { // "perspective"
785 G4String dummy;
786 G4String unit;
787 std::istringstream is (newValue);
788 is >> dummy >> fieldHalfAngle >> unit;
789 fieldHalfAngle *= G4UIcommand::ValueOf(unit);
790 if (fieldHalfAngle > 89.5 * deg || fieldHalfAngle <= 0.0) {
791 if (verbosity >= G4VisManager::errors) {
792 G4cout <<
793 "ERROR: Field half angle should be 0 < angle <= 89.5 degrees.";
794 G4cout << G4endl;
795 }
796 return;
797 }
798 }
799 else {
800 if (verbosity >= G4VisManager::errors) {
801 G4cout << "ERROR: \"" << newValue << "\" not recognised."
802 " Looking for 'o' or 'p' first character." << G4endl;
803 }
804 return;
805 }
806 vp.SetFieldHalfAngle(fieldHalfAngle);
807 if (verbosity >= G4VisManager::confirmations) {
808 G4cout << "Projection style of viewer \"" << currentViewer->GetName()
809 << "\" set to ";
810 if (fieldHalfAngle == 0.) {
811 G4cout << "orthogonal.";
812 }
813 else {
814 G4cout << "perspective\n with half angle " << fieldHalfAngle / deg
815 << " degrees.";
816 }
817 G4cout << G4endl;
818 }
819 }
820
821 else if (command == fpCommandSectionPlane) {
822 G4String choice, unit;
823 G4double x, y, z, nx, ny, nz;
824 std::istringstream is (newValue);
825 is >> choice >> x >> y >> z >> unit >> nx >> ny >> nz;
826
827 G4int iSelector = -1;
828 if (choice.compareTo("off",G4String::ignoreCase) == 0 ||
829 !G4UIcommand::ConvertToBool(choice)) iSelector = 0;
830 if (choice.compareTo("on",G4String::ignoreCase) == 0 ||
831 G4UIcommand::ConvertToBool(choice)) iSelector = 1;
832 if (iSelector < 0) {
833 if (verbosity >= G4VisManager::errors) {
834 G4cout << "Choice not recognised (on/true or off/false)." << G4endl;
835 G4cout << "Section drawing is currently: ";
836 if (vp.IsSection ()) G4cout << "on";
837 else G4cout << "off";
838 G4cout << ".\nSection plane is currently: "
839 << vp.GetSectionPlane ();
840 G4cout << G4endl;
841 }
842 return;
843 }
844
845 G4double F = 1.;
846 switch (iSelector) {
847 default:
848 case 0:
849 vp.UnsetSectionPlane();
850 break;
851 case 1:
852 F = G4UIcommand::ValueOf(unit);
853 x *= F; y *= F; z *= F;
854 vp.SetSectionPlane(G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
855 vp.SetViewpointDirection(G4Normal3D(nx,ny,nz));
856 break;
857 }
858
859 if (verbosity >= G4VisManager::confirmations) {
860 G4cout << "Section drawing is now: ";
861 if (vp.IsSection ()) G4cout << "on";
862 else G4cout << "off";
863 G4cout << ".\nSection plane is now: "
864 << vp.GetSectionPlane ();
865 G4cout << G4endl;
866 }
867 }
868
869 else if (command == fpCommandStyle) {
870 G4ViewParameters::DrawingStyle existingStyle = vp.GetDrawingStyle();
871 const size_t iPos0 = 0;
872 if (newValue[iPos0] == 'w') { // "wireframe"
873 switch (existingStyle) {
874 case G4ViewParameters::wireframe:
875 break;
876 case G4ViewParameters::hlr:
877 break;
878 case G4ViewParameters::hsr:
879 vp.SetDrawingStyle(G4ViewParameters::wireframe);
880 break;
881 case G4ViewParameters::hlhsr:
882 vp.SetDrawingStyle(G4ViewParameters::hlr);
883 break;
884 }
885 }
886 else if (newValue[iPos0] == 's') { // "surface"
887 switch (existingStyle) {
888 case G4ViewParameters::wireframe:
889 vp.SetDrawingStyle(G4ViewParameters::hsr);
890 break;
891 case G4ViewParameters::hlr:
892 vp.SetDrawingStyle(G4ViewParameters::hlhsr);
893 break;
894 case G4ViewParameters::hsr:
895 break;
896 case G4ViewParameters::hlhsr:
897 break;
898 }
899 }
900 else {
901 if (verbosity >= G4VisManager::errors) {
902 G4cout << "ERROR: \"" << newValue << "\" not recognised."
903 " Looking for 'w' or 's' first character." << G4endl;
904 }
905 return;
906 }
907 if (verbosity >= G4VisManager::confirmations) {
908 G4cout << "Drawing style of viewer \"" << currentViewer->GetName()
909 << "\" set to " << vp.GetDrawingStyle()
910 << G4endl;
911 }
912 }
913
914 else if (command == fpCommandUpThetaPhi) {
915 G4double theta, phi;
916 ConvertToDoublePair(newValue, theta, phi);
917 G4double x = std::sin (theta) * std::cos (phi);
918 G4double y = std::sin (theta) * std::sin (phi);
919 G4double z = std::cos (theta);
920 fUpVector = G4ThreeVector (x, y, z);
921 vp.SetUpVector(fUpVector);
922 if (verbosity >= G4VisManager::confirmations) {
923 G4cout << "Up direction set to " << vp.GetUpVector() << G4endl;
924 }
925 }
926
927 else if (command == fpCommandUpVector) {
928 fUpVector = G4UIcommand::ConvertTo3Vector(newValue).unit();
929 vp.SetUpVector(fUpVector);
930 if (verbosity >= G4VisManager::confirmations) {
931 G4cout << "Up direction set to " << vp.GetUpVector() << G4endl;
932 }
933 }
934
935 else if (command == fpCommandViewpointThetaPhi) {
936 G4double theta, phi;
937 ConvertToDoublePair(newValue, theta, phi);
938 G4double x = std::sin (theta) * std::cos (phi);
939 G4double y = std::sin (theta) * std::sin (phi);
940 G4double z = std::cos (theta);
941 fViewpointVector = G4ThreeVector (x, y, z);
942 vp.SetViewAndLights(fViewpointVector);
943 if (verbosity >= G4VisManager::confirmations) {
944 G4cout << "Viewpoint direction set to "
945 << vp.GetViewpointDirection() << G4endl;
946 if (vp.GetLightsMoveWithCamera ()) {
947 G4cout << "Lightpoint direction set to "
948 << vp.GetActualLightpointDirection () << G4endl;
949 }
950 }
951 }
952
953 else if (command == fpCommandViewpointVector) {
954 fViewpointVector = G4UIcommand::ConvertTo3Vector(newValue).unit();
955 vp.SetViewAndLights(fViewpointVector);
956 if (verbosity >= G4VisManager::confirmations) {
957 G4cout << "Viewpoint direction set to "
958 << vp.GetViewpointDirection() << G4endl;
959 if (vp.GetLightsMoveWithCamera ()) {
960 G4cout << "Lightpoint direction set to "
961 << vp.GetActualLightpointDirection () << G4endl;
962 }
963 }
964 }
965
966 else {
967 if (verbosity >= G4VisManager::errors) {
968 G4cout <<
969 "ERROR: G4VisCommandsViewerSet::SetNewValue: unrecognised command."
970 << G4endl;
971 }
972 return;
973 }
974
975 SetViewParameters(currentViewer,vp);
976}
Note: See TracBrowser for help on using the repository browser.