56 std::ostringstream ost;
147 unsigned int winWidth = 0, winHeight = 0;
150 if ((
fVP.IsZoomToCursor() || shift) && sceneWidth > 0 && winSizeOk) {
153 G4double minWidth = winWidth > winHeight ? winHeight : winWidth;
156 G4double xi = px * sceneWidth / minWidth;
157 G4double yi = py * sceneWidth / minWidth;
160 if (
fVP.GetFieldHalfAngle() == 0.) {
162 G4double zoomFactor = 1. + std::abs(
double(delta)) / 1200;
163 if (delta < 0) zoomFactor = 1. / zoomFactor;
171 fVP.MultiplyZoomFactor(zoomFactor);
172 fVP.IncrementPan(-deltaX, -deltaY, 0);
177 if (radius <= 0.) radius = 1.;
178 const G4double cameraDistance =
fVP.GetCameraDistance(radius);
179 const G4double pnear =
fVP.GetNearDistance(cameraDistance, radius);
181 G4double deltaDolly = 0.1 * cameraDistance * std::abs(delta) / 120;
182 if (delta < 0) deltaDolly = -deltaDolly;
184 G4double deltaX = -xi * deltaDolly / pnear;
185 G4double deltaY = -yi * deltaDolly / pnear;
189 fVP.IncrementDolly(deltaDolly);
190 fVP.IncrementPan(-deltaX, -deltaY, 0);
195 if (
fVP.GetFieldHalfAngle() == 0.) {
197 G4double zoomFactor = 1. + std::abs(
double(delta)) / 1200;
198 if (delta < 0) zoomFactor = 1. / zoomFactor;
199 fVP.MultiplyZoomFactor(zoomFactor);
204 if (radius <= 0.) radius = 1.;
205 const G4double cameraDistance =
fVP.GetCameraDistance(radius);
207 G4double deltaDolly = 0.1 * cameraDistance * std::abs(delta) / 120;
208 if (delta < 0) deltaDolly = -deltaDolly;
211 fVP.IncrementDolly(deltaDolly);
222 const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath)
225 std::ostringstream oss;
227 for (
const auto& pvNodeId : fullPath) {
228 const auto& pv = pvNodeId.GetPhysicalVolume();
229 auto iterator = find(pvStore->cbegin(), pvStore->cend(), pv);
230 if (iterator == pvStore->cend()) {
232 ed <<
"Volume no longer in physical volume store.";
236 oss <<
' ' << pvNodeId.GetPhysicalVolume()->GetName() <<
' ' << pvNodeId.GetCopyNo();
243 const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath,
G4bool visibiity)
266 std::list<G4SceneTreeItem>::iterator foundIter;
267 if (
fSceneTree.FindTouchableFromRoot(fullPathString, foundIter)) {
268 foundIter->AccessVisAttributes().SetVisibility(visibiity);
273 ed <<
"Touchable \"" << fullPath <<
"\" not found";
279 const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& fullPath,
303 std::list<G4SceneTreeItem>::iterator foundIter;
304 if (
fSceneTree.FindTouchableFromRoot(fullPathString, foundIter)) {
305 foundIter->AccessVisAttributes().SetColour(colour);
310 ed <<
"Touchable \"" << fullPath <<
"\" not found";
348 const auto& modelType = model->
GetType();
357 static G4bool firstWarning =
true;
360 const auto& nAllTouchables = pvModel->GetTotalAllTouchables();
362 std::ostringstream oss;
363 oss << nAllTouchables <<
" touchables - too many for scene tree";
364 furtherInfo = oss.str();
369 ed << pvModel->GetGlobalDescription() <<
370 ":\n Too many touchables (" << nAllTouchables
371 <<
") for scene tree. Scene tree for this model will be empty.";
378 if (warned) firstWarning =
false;
381 auto& modelItems =
fSceneTree.AccessChildren();
382 auto modelIter = modelItems.begin();
383 auto pvModelIter = modelItems.end();
384 for (; modelIter != modelItems.end(); ++modelIter) {
386 pvModelIter = modelIter;
388 if (modelIter->GetModelDescription() == modelDescription)
break;
391 if (modelIter == modelItems.end()) {
397 if (pvModelIter != modelItems.end() &&
399 fSceneTree.InsertChild(++pvModelIter, modelItem);
404 modelIter->AccessVisAttributes().SetVisibility(
true);
412 if (fpPVModel ==
nullptr) {
414 "G4PhysicalVolumeModel pointer is null");
420 for (
const auto& dn : fpPVModel->GetMapOfDrawnTouchables()) {
421 expanded += dn.second;
422 if (fMaximumExpandedDepth < dn.first) fMaximumExpandedDepth = dn.first;
423 if (expanded > fMaximumExpanded) break;
427 const auto& modelID = fpPVModel->GetGlobalDescription();
428 auto& modelItems = fpViewer->fSceneTree.AccessChildren();
429 fModelIter = modelItems.begin();
430 for (; fModelIter != modelItems.end(); ++fModelIter) {
431 if (fModelIter->GetModelDescription() == modelID)
break;
433 if (fModelIter == modelItems.end()) {
434 G4Exception(
"G4VViewer::SceneTreeScene::SceneTreeScene",
"visman0406", JustWarning,
439void G4VViewer::SceneTreeScene::ProcessVolume(
const G4VSolid&)
441 if (fpViewer->fCurtailDescent) {
442 fpPVModel->CurtailDescent();
446 const auto& modelID = fpPVModel->GetGlobalDescription();
448 std::ostringstream oss;
449 oss << fpPVModel->GetFullPVPath();
454 const auto& nodeIDs = fpPVModel->GetFullPVPath();
456 auto currentIter = fModelIter;
458 for (
const auto& nodeID : nodeIDs) {
459 std::ostringstream oss1;
461 partialPathString +=
' ' + oss1.str();
463 FindOrInsertTouchable(modelID, *currentIter, ++depth, partialPathString, fullPathString);
468std::list<G4SceneTreeItem>::iterator G4VViewer::SceneTreeScene::FindOrInsertTouchable
469 (
const G4String& modelID, G4SceneTreeItem& mother,
470 G4int depth,
const G4String& partialPathString,
const G4String& fullPathString)
473 auto childIter = children.begin();
474 for (; childIter != children.end(); ++childIter) {
475 if (childIter->GetPVPath() == partialPathString)
break;
477 if (childIter != children.end()) {
485 if (partialPathString == fullPathString) {
489 childIter->SetDescription(fpPVModel->GetCurrentTag());
490 childIter->SetModelType(fpPVModel->GetType());
491 childIter->SetModelDescription(modelID);
492 childIter->SetPVPath(partialPathString);
493 if (fpVisAttributes) childIter->SetVisAttributes(*fpVisAttributes);
494 childIter->SetAttDefs(fpPVModel->GetAttDefs());
495 childIter->SetAttValues(fpPVModel->CreateCurrentAttValues());
502 if (partialPathString == fullPathString) {
505 if (fpVisAttributes) childIter->SetVisAttributes(*fpVisAttributes);
514 if (partialPathString == fullPathString) {
519 touchable.SetExpanded(depth > fMaximumExpandedDepth?
false:
true);
520 touchable.SetDescription(fpPVModel->GetCurrentTag());
521 touchable.SetModelType(fpPVModel->GetType());
522 touchable.SetModelDescription(modelID);
523 touchable.SetPVPath(partialPathString);
524 if (fpVisAttributes) touchable.SetVisAttributes(*fpVisAttributes);
525 touchable.SetAttDefs(fpPVModel->GetAttDefs());
526 touchable.SetAttValues(fpPVModel->CreateCurrentAttValues());
527 childIter = mother.
InsertChild(childIter,touchable);
533 ghost.SetExpanded(depth > fMaximumExpandedDepth?
false:
true);
535 std::istringstream iss(partialPathString);
536 G4String
name, copyNo;
537 while (iss >> name >> copyNo);
538 std::ostringstream oss;
539 oss <<
name <<
':' << copyNo;
540 ghost.SetDescription(oss.str());
541 ghost.SetModelType(fpPVModel->GetType());
542 ghost.SetModelDescription(modelID);
543 ghost.SetPVPath(partialPathString);
544 ghost.AccessVisAttributes().SetVisibility(
false);
555 os <<
"View " << v.
fName <<
":\n";
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
static G4String GetPVNamePathString(const std::vector< G4PhysicalVolumeNodeID > &)
static G4ModelingParameters::PVNameCopyNoPath GetPVNameCopyNoPath(const std::vector< G4PhysicalVolumeNodeID > &)
static G4PhysicalVolumeStore * GetInstance()
void SetModelDescription(const G4String &modelDescription)
void SetDescription(const G4String &description)
std::list< G4SceneTreeItem > & AccessChildren()
std::list< G4SceneTreeItem >::iterator InsertChild(std::list< G4SceneTreeItem >::iterator pos, const G4SceneTreeItem &item)
void SetFurtherInfo(const G4String &furtherInfo)
void SetModelType(const G4String &modelType)
G4double GetRealElapsed() const
G4int ApplyCommand(const char *aCommand)
G4UIsession * GetG4UIWindow() const
static G4UImanager * GetUIpointer()
virtual void UpdateTransparencySlider(G4double depth, G4int option)
virtual void UpdateSceneTree(const G4SceneTreeItem &)
virtual void UpdateDrawingStyle(G4int style)
virtual void UpdateProjectionStyle(G4int style)
const G4String & GetGlobalDescription() const
const G4String & GetType() const
G4VSolid is an abstract base class for solids, physical shapes that can be tracked through....
SceneTreeScene(G4VViewer *, G4PhysicalVolumeModel *)
void SetTouchable(const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath)
void SetName(const G4String &)
friend std::ostream & operator<<(std::ostream &os, const G4VViewer &v)
const G4int fMaxAllTouchables
virtual G4double GetSceneNearWidth()
G4VSceneHandler & fSceneHandler
G4double fKernelVisitElapsedTimeSeconds
void UpdateGUITransparencySlider()
void UpdateGUIControlWidgets()
void UpdateGUISceneTree()
void InsertModelInSceneTree(G4VModel *)
G4ViewParameters fDefaultVP
G4bool fTransientsNeedRedrawing
void UpdateGUIDrawingStyle()
virtual G4bool GetWindowSize(unsigned int &a_w, unsigned int &a_h)
void TouchableSetVisibility(const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, G4bool visibility)
void UpdateGUIProjectionStyle()
virtual void FinishView()
G4VViewer(G4VSceneHandler &, G4int id, const G4String &name="")
void SetViewParameters(const G4ViewParameters &vp)
void TouchableSetColour(const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, const G4Colour &)
void ZoomFromMouseWheel(G4double delta, G4bool shift=false, G4double xPos=0, G4double yPos=0)
G4SceneTreeItem fSceneTree
void SetColour(const G4Colour &)
void SetVisibility(G4bool=true)
static G4VisManager * GetInstance()
const char * name(G4int ptype)
void strip(G4String &str, char ch=' ')
Remove leading and trailing characters from string.