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
00026
00027
00028
00029
00030
00031 #include "G4VisCommandsTouchableSet.hh"
00032
00033 #include "G4UIcommand.hh"
00034 #include "G4UIcmdWithABool.hh"
00035 #include "G4UIcmdWithADouble.hh"
00036 #include "G4UIcmdWithAnInteger.hh"
00037 #include "G4UIcmdWithAString.hh"
00038
00039 #include <sstream>
00040 #include <cctype>
00041
00043
00044 G4VisCommandsTouchableSet::G4VisCommandsTouchableSet()
00045 {
00046 G4bool omitable;
00047 G4UIparameter* parameter;
00048
00049 fpCommandSetColour = new G4UIcommand
00050 ("/vis/touchable/set/colour", this);
00051 fpCommandSetColour->SetGuidance("Set colour of current touchable.");
00052 fpCommandSetColour->SetGuidance
00053 ("Use \"/vis/set/touchable\" to set current touchable.");
00054 parameter = new G4UIparameter("red", 's', omitable = true);
00055 parameter->SetDefaultValue("1.");
00056 parameter->SetGuidance
00057 ("Red component or a string, e.g., \"blue\", in which case succeeding colour"
00058 "\ncomponents are ignored.");
00059 fpCommandSetColour->SetParameter(parameter);
00060 parameter = new G4UIparameter("green", 'd', omitable = true);
00061 parameter->SetDefaultValue(1.);
00062 fpCommandSetColour->SetParameter(parameter);
00063 parameter = new G4UIparameter("blue", 'd', omitable = true);
00064 parameter->SetDefaultValue(1.);
00065 fpCommandSetColour->SetParameter(parameter);
00066 parameter = new G4UIparameter("opacity", 'd', omitable = true);
00067 parameter->SetDefaultValue(1.);
00068 fpCommandSetColour->SetParameter(parameter);
00069
00070 fpCommandSetDaughtersInvisible = new G4UIcmdWithABool
00071 ("/vis/touchable/set/daughtersInvisible", this);
00072 fpCommandSetDaughtersInvisible->SetGuidance
00073 ("Daughters of current touchable invisible: true/false.");
00074 fpCommandSetDaughtersInvisible->SetGuidance
00075 ("Use \"/vis/set/touchable\" to set current touchable.");
00076 fpCommandSetDaughtersInvisible->SetParameterName("daughtersInvisible", omitable = true);
00077 fpCommandSetDaughtersInvisible->SetDefaultValue(false);
00078
00079 fpCommandSetForceAuxEdgeVisible = new G4UIcmdWithABool
00080 ("/vis/touchable/set/forceAuxEdgeVisible", this);
00081 fpCommandSetForceAuxEdgeVisible->SetGuidance
00082 ("Force auxiliary (soft) edges of current touchable to be visible:"
00083 " true/false.");
00084 fpCommandSetForceAuxEdgeVisible->SetGuidance
00085 ("Use \"/vis/set/touchable\" to set current touchable.");
00086 fpCommandSetForceAuxEdgeVisible->SetParameterName("forceAuxEdgeVisible", omitable = true);
00087 fpCommandSetForceAuxEdgeVisible->SetDefaultValue(false);
00088
00089 fpCommandSetLineSegmentsPerCircle = new G4UIcmdWithAnInteger
00090 ("/vis/touchable/set/lineSegmentsPerCircle", this);
00091 fpCommandSetLineSegmentsPerCircle->SetGuidance
00092 ("For current touchable, set number of line segments per circle, the"
00093 "\nprecision with which a curved line or surface is represented by a"
00094 "\npolygon or polyhedron, regardless of the view parameters."
00095 "\nNegative to pick up G4Polyhedron default value.");
00096 fpCommandSetLineSegmentsPerCircle->SetGuidance
00097 ("Use \"/vis/set/touchable\" to set current touchable.");
00098 fpCommandSetLineSegmentsPerCircle->SetParameterName("lineSegmentsPerCircle", omitable = true);
00099 fpCommandSetLineSegmentsPerCircle->SetDefaultValue(-1);
00100
00101 fpCommandSetForceSolid = new G4UIcmdWithABool
00102 ("/vis/touchable/set/forceSolid", this);
00103 fpCommandSetForceSolid->SetGuidance
00104 ("Force current touchable always to be drawn solid (surface drawing).");
00105 fpCommandSetForceSolid->SetGuidance
00106 ("Use \"/vis/set/touchable\" to set current touchable.");
00107 fpCommandSetForceSolid->SetParameterName("forceSolid", omitable = true);
00108 fpCommandSetForceSolid->SetDefaultValue(false);
00109
00110 fpCommandSetForceWireframe = new G4UIcmdWithABool
00111 ("/vis/touchable/set/forceWireframe", this);
00112 fpCommandSetForceWireframe->SetGuidance
00113 ("Force current touchable always to be drawn as wireframe.");
00114 fpCommandSetForceWireframe->SetGuidance
00115 ("Use \"/vis/set/touchable\" to set current touchable.");
00116 fpCommandSetForceWireframe->SetParameterName("forceWireframe", omitable = true);
00117 fpCommandSetForceWireframe->SetDefaultValue(false);
00118
00119 fpCommandSetLineStyle = new G4UIcmdWithAString
00120 ("/vis/touchable/set/lineStyle", this);
00121 fpCommandSetLineStyle->SetGuidance("Set line style of current touchable drawing.");
00122 fpCommandSetLineStyle->SetGuidance
00123 ("Use \"/vis/set/touchable\" to set current touchable.");
00124 fpCommandSetLineStyle->SetParameterName("lineStyle", omitable = true);
00125 fpCommandSetLineStyle->SetCandidates("unbroken dashed dotted");
00126 fpCommandSetLineStyle->SetDefaultValue("unbroken");
00127
00128 fpCommandSetLineWidth = new G4UIcmdWithADouble
00129 ("/vis/touchable/set/lineWidth", this);
00130 fpCommandSetLineWidth->SetGuidance("Set line width of current touchable.");
00131 fpCommandSetLineWidth->SetGuidance
00132 ("Use \"/vis/set/touchable\" to set current touchable.");
00133 fpCommandSetLineWidth->SetParameterName("lineWidth", omitable = true);
00134 fpCommandSetLineWidth->SetDefaultValue(1.);
00135
00136 fpCommandSetVisibility = new G4UIcmdWithABool
00137 ("/vis/touchable/set/visibility", this);
00138 fpCommandSetVisibility->SetGuidance
00139 ("Set visibility of current touchable: true/false.");
00140 fpCommandSetVisibility->SetGuidance
00141 ("Use \"/vis/set/touchable\" to set current touchable.");
00142 fpCommandSetVisibility->SetParameterName("visibility", omitable = true);
00143 fpCommandSetVisibility->SetDefaultValue(false);
00144 }
00145
00146 G4VisCommandsTouchableSet::~G4VisCommandsTouchableSet() {
00147 delete fpCommandSetVisibility;
00148 delete fpCommandSetLineWidth;
00149 delete fpCommandSetLineStyle;
00150 delete fpCommandSetForceWireframe;
00151 delete fpCommandSetForceSolid;
00152 delete fpCommandSetLineSegmentsPerCircle;
00153 delete fpCommandSetForceAuxEdgeVisible;
00154 delete fpCommandSetDaughtersInvisible;
00155 delete fpCommandSetColour;
00156 }
00157
00158 G4String G4VisCommandsTouchableSet::GetCurrentValue(G4UIcommand*) {
00159 return "";
00160 }
00161
00162 void G4VisCommandsTouchableSet::SetNewValue
00163 (G4UIcommand* command,G4String newValue)
00164 {
00165 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00166
00167 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
00168 if (!currentViewer) {
00169 if (verbosity >= G4VisManager::errors) {
00170 G4cout <<
00171 "ERROR: G4VisCommandsTouchableSet::SetNewValue: no current viewer."
00172 << G4endl;
00173 }
00174 return;
00175 }
00176
00177 G4ViewParameters workingVP = currentViewer->GetViewParameters();
00178 G4VisAttributes workingVisAtts;
00179
00180 if (command == fpCommandSetColour)
00181 {
00182 G4String redOrString;
00183 G4double green, blue, opacity;
00184 std::istringstream iss(newValue);
00185 iss >> redOrString >> green >> blue >> opacity;
00186 G4Colour colour(1,1,1,1);
00187 const size_t iPos0 = 0;
00188 if (std::isalpha(redOrString[iPos0])) {
00189 if (!G4Colour::GetColour(redOrString, colour)) {
00190 if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
00191 G4cout << "WARNING: Colour \"" << redOrString
00192 << "\" not found. Defaulting to white and opaque."
00193 << G4endl;
00194 }
00195 }
00196 } else {
00197 colour = G4Colour(G4UIcommand::ConvertToDouble(redOrString), green, blue);
00198 }
00199 colour = G4Colour
00200 (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity);
00201
00202 workingVisAtts.SetColour(colour);
00203 workingVP.AddVisAttributesModifier
00204 (G4ModelingParameters::VisAttributesModifier
00205 (workingVisAtts,
00206 G4ModelingParameters::VASColour,
00207 fCurrentTouchablePath));
00208 }
00209
00210 else if (command == fpCommandSetDaughtersInvisible) {
00211 workingVisAtts.SetDaughtersInvisible(G4UIcommand::ConvertToBool(newValue));
00212 workingVP.AddVisAttributesModifier
00213 (G4ModelingParameters::VisAttributesModifier
00214 (workingVisAtts,
00215 G4ModelingParameters::VASDaughtersInvisible,
00216 fCurrentTouchablePath));
00217 }
00218
00219 else if (command == fpCommandSetForceAuxEdgeVisible) {
00220 workingVisAtts.SetForceAuxEdgeVisible(G4UIcommand::ConvertToBool(newValue));
00221 workingVP.AddVisAttributesModifier
00222 (G4ModelingParameters::VisAttributesModifier
00223 (workingVisAtts,
00224 G4ModelingParameters::VASForceAuxEdgeVisible,
00225 fCurrentTouchablePath));
00226 }
00227
00228 else if (command == fpCommandSetLineSegmentsPerCircle) {
00229 workingVisAtts.SetForceLineSegmentsPerCircle
00230 (G4UIcommand::ConvertToInt(newValue));
00231 workingVP.AddVisAttributesModifier
00232 (G4ModelingParameters::VisAttributesModifier
00233 (workingVisAtts,
00234 G4ModelingParameters::VASForceLineSegmentsPerCircle,
00235 fCurrentTouchablePath));
00236 }
00237
00238 else if (command == fpCommandSetForceSolid) {
00239 workingVisAtts.SetForceSolid(G4UIcommand::ConvertToBool(newValue));
00240 workingVP.AddVisAttributesModifier
00241 (G4ModelingParameters::VisAttributesModifier
00242 (workingVisAtts,
00243 G4ModelingParameters::VASForceSolid,
00244 fCurrentTouchablePath));
00245 }
00246
00247 else if (command == fpCommandSetForceWireframe) {
00248 workingVisAtts.SetForceWireframe(G4UIcommand::ConvertToBool(newValue));
00249 workingVP.AddVisAttributesModifier
00250 (G4ModelingParameters::VisAttributesModifier
00251 (workingVisAtts,
00252 G4ModelingParameters::VASForceWireframe,
00253 fCurrentTouchablePath));
00254 }
00255
00256 else if (command == fpCommandSetLineStyle) {
00257 G4VisAttributes::LineStyle lineStyle = G4VisAttributes::unbroken;
00258 if (newValue == "dashed") {
00259 lineStyle = G4VisAttributes::dashed;
00260 } else if (newValue == "dotted") {
00261 lineStyle = G4VisAttributes::dotted;
00262 }
00263
00264 workingVisAtts.SetLineStyle(lineStyle);
00265 workingVP.AddVisAttributesModifier
00266 (G4ModelingParameters::VisAttributesModifier
00267 (workingVisAtts,
00268 G4ModelingParameters::VASLineStyle,
00269 fCurrentTouchablePath));
00270 }
00271
00272 else if (command == fpCommandSetLineWidth) {
00273 workingVisAtts.SetLineWidth(G4UIcommand::ConvertToDouble(newValue));
00274 workingVP.AddVisAttributesModifier
00275 (G4ModelingParameters::VisAttributesModifier
00276 (workingVisAtts,
00277 G4ModelingParameters::VASLineWidth,
00278 fCurrentTouchablePath));
00279 }
00280
00281 else if (command == fpCommandSetVisibility) {
00282 workingVisAtts.SetVisibility(G4UIcommand::ConvertToBool(newValue));
00283 workingVP.AddVisAttributesModifier
00284 (G4ModelingParameters::VisAttributesModifier
00285 (workingVisAtts,
00286 G4ModelingParameters::VASVisibility,
00287 fCurrentTouchablePath));
00288 }
00289
00290 else {
00291 if (verbosity >= G4VisManager::errors) {
00292 G4cout <<
00293 "ERROR: G4VisCommandsTouchableSet::SetNewValue: unrecognised command."
00294 << G4endl;
00295 }
00296 return;
00297 }
00298
00299 SetViewParameters(currentViewer,workingVP);
00300 }