2093 {
2094
2097
2099 if (!pScene) {
2101 G4cerr <<
"ERROR: No current scene. Please create one." <<
G4endl;
2102 }
2103 return;
2104 } else {
2108 << "ERROR: Scene has no extent. Add volumes or use \"/vis/scene/add/extent\"."
2110 }
2111 return;
2112 }
2113 }
2114
2115 G4double userLength, red, green, blue, xmid, ymid, zmid;
2116 G4String userLengthUnit, direction, auto_manual, positionUnit;
2117 std::istringstream is (newValue);
2118 is >> userLength >> userLengthUnit >> direction
2119 >> red >> green >> blue
2120 >> auto_manual
2121 >> xmid >> ymid >> zmid >> positionUnit;
2122
2125 if (userLengthUnit == "auto") {
2127 const G4double intLog10Length = std::floor(std::log10(lengthMax));
2128 length = std::pow(10,intLog10Length);
2129 if (5.*length < lengthMax) length *= 5.;
2130 else if (2.*length < lengthMax) length *= 2.;
2131 } else {
2133 }
2135
2137 xmid *= unit; ymid *= unit; zmid *= unit;
2138
2140 if (direction(0) ==
'y') scaleDirection =
G4Scale::y;
2141 if (direction(0) ==
'z') scaleDirection =
G4Scale::z;
2142
2144 if (!pViewer) {
2147 "ERROR: G4VisCommandSceneAddScale::SetNewValue: no viewer."
2148 "\n Auto direction needs a viewer."
2150 }
2151 return;
2152 }
2153
2158
2159 if (direction == "auto") {
2160 if (std::abs(vp.
x()) > std::abs(vp.
y()) &&
2161 std::abs(vp.
x()) > std::abs(vp.
z())) {
2162 if (std::abs(up.
y()) > std::abs(up.
z())) scaleDirection =
G4Scale::z;
2164 }
2165 else if (std::abs(vp.
y()) > std::abs(vp.
x()) &&
2166 std::abs(vp.
y()) > std::abs(vp.
z())) {
2167 if (std::abs(up.
x()) > std::abs(up.
z())) scaleDirection =
G4Scale::z;
2169 }
2170 else if (std::abs(vp.
z()) > std::abs(vp.
x()) &&
2171 std::abs(vp.
z()) > std::abs(vp.
y())) {
2172 if (std::abs(up.
y()) > std::abs(up.
x())) scaleDirection =
G4Scale::x;
2174 }
2175 }
2176
2177 G4bool autoPlacing =
false;
if (auto_manual ==
"auto") autoPlacing =
true;
2178
2179
2180
2181 const G4double halfLength(length / 2.);
2183 const G4double freeLengthFraction (1. + 2. * comfort);
2184
2191
2192
2195 worried = true;
2198 "WARNING: Existing scene does not yet have any extent."
2199 "\n Maybe you have not yet added any geometrical object."
2201 }
2202 }
2203
2205 switch (scaleDirection) {
2207 if (freeLengthFraction * (xmax - xmin) < length) room = false;
2208 break;
2210 if (freeLengthFraction * (ymax - ymin) < length) room = false;
2211 break;
2213 if (freeLengthFraction * (zmax - zmin) < length) room = false;
2214 break;
2215 }
2216 if (!room) {
2217 worried = true;
2220 "WARNING: Not enough room in existing scene. Maybe scale is too long."
2222 }
2223 }
2224 if (worried) {
2227 "WARNING: The scale you have asked for is bigger than the existing"
2228 "\n scene. Maybe you have added it too soon. It is recommended that"
2229 "\n you add the scale last so that it can be correctly auto-positioned"
2230 "\n so as not to be obscured by any existing object and so that the"
2231 "\n view parameters can be correctly recalculated."
2233 }
2234 }
2235
2236
2237
2238 G4Scale scale(length, annotation, scaleDirection,
2239 false, xmid, ymid, zmid,
2242 scale.SetVisAttributes(visAttr);
2245 globalDescription += " (" + newValue + ")";
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275 G4double sxmid(xmid), symid(ymid), szmid(zmid);
2276 if (autoPlacing) {
2277
2278
2279 const G4double xComfort = comfort * (xmax - xmin);
2280 const G4double yComfort = comfort * (ymax - ymin);
2281 const G4double zComfort = comfort * (zmax - zmin);
2282 switch (scaleDirection) {
2285 sxmid = xmax + xComfort;
2286 symid = ymin - yComfort;
2287 szmid = zmin - zComfort;
2288 } else {
2289 sxmid = xmin - xComfort;
2290 symid = ymin - yComfort;
2291 szmid = zmax + zComfort;
2292 }
2293 break;
2296 sxmid = xmin - xComfort;
2297 symid = ymax + yComfort;
2298 szmid = zmin - zComfort;
2299 } else {
2300 sxmid = xmax + xComfort;
2301 symid = ymin - yComfort;
2302 szmid = zmin - zComfort;
2303 }
2304 break;
2307 sxmid = xmax + xComfort;
2308 symid = ymin - yComfort;
2309 szmid = zmax + zComfort;
2310 } else {
2311 sxmid = xmin - xComfort;
2312 symid = ymin - yComfort;
2313 szmid = zmax + zComfort;
2314 }
2315 break;
2316 }
2317 }
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2369 switch (scaleDirection) {
2371 scaleExtent =
G4VisExtent(-halfLength,halfLength,0,0,0,0);
2372 break;
2375 scaleExtent =
G4VisExtent(0,0,-halfLength,halfLength,0,0);
2376 break;
2379 scaleExtent =
G4VisExtent(0,0,0,0,-halfLength,halfLength);
2380 break;
2381 }
2383
2384
2386
2387
2389
2390
2391
2392 const G4String& currentSceneName = pScene -> GetName ();
2393 G4bool successful = pScene -> AddRunDurationModel (model, warn);
2394 if (successful) {
2396 G4cout <<
"Scale of " << annotation
2397 << " added to scene \"" << currentSceneName << "\".";
2399 G4cout <<
"\n with extent " << scaleExtent
2402 }
2404 }
2405 }
2407
2409}
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
const G4VisExtent & GetExtent() const
static G4double ValueOf(const char *unitName)
void SetGlobalDescription(const G4String &)
void SetExtent(const G4VisExtent &)
const G4String & GetGlobalDescription() const
void SetTransformation(const G4Transform3D &)
const G4ViewParameters & GetViewParameters() const
static G4double fCurrentTextSize
void G4VisCommandsSceneAddUnsuccessful(G4VisManager::Verbosity verbosity)
void CheckSceneAndNotifyHandlers(G4Scene *=nullptr)
static G4VisManager * fpVisManager
const G4Vector3D & GetViewpointDirection() const
const G4Vector3D & GetUpVector() const
G4double GetExtentRadius() const
G4Scene * GetCurrentScene() const
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()