Skip to content

Commit f3fb956

Browse files
authored
Merge pull request #2381 from willend/main
Changed (hard-coded) mcgui 3D visualiser to be webgl-classic
2 parents 4c06b20 + 08035d9 commit f3fb956

5 files changed

Lines changed: 33 additions & 27 deletions

File tree

tools/Python/mccodelib/instrgeom.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ def _get_points(self):
578578
elif self.plane == 'yz':
579579
return map(lambda p: cen.add(Vector3d(0, p.x, p.y)), square)
580580
else:
581-
raise Exception('DrawCircle: invalid plane argument')
581+
# Fallback to xy
582+
return map(lambda p: cen.add(p), square)
582583

583584
def get_points_on_circle(self, steps=60):
584585
''' returns points on the circle, transformed into the proper plane '''

tools/Python/mccodelib/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,7 @@ def call_if_not_none(fct, *args):
918918
''' shorthand utility for calling a function if it is defined, and otherwise ignoring it '''
919919
if fct:
920920
fct(*args)
921+
921922
if not cwd:
922923
cwd = os.getcwd()
923924

tools/Python/mcgui/mcgui.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,23 @@ def run(self, fixed_params, params, inspect=None):
459459
self.__emitter.status('Started simulation/trace in background shell...')
460460
subprocess.Popen(runstr, shell=True)
461461

462+
def vis_run(self, tool=''):
463+
464+
runstr = tool + ' ' + os.path.basename(self.__instrFile) + ' -n100 -y'
465+
466+
# Add & for backgrounding on Unix systems
467+
if not os.name == 'nt':
468+
runstr = runstr + ' &'
469+
else:
470+
runstr = 'start ' + runstr
471+
472+
# Ensure assembled runstr is a string, not a QString
473+
runstr = str(runstr)
474+
475+
self.__emitter.status('Starting visualisation in background shell...')
476+
self.__emitter.message(runstr, gui=False)
477+
subprocess.Popen(runstr, shell=True)
478+
462479
def __runFinished(self, process_returncode):
463480
self.__fireSimStateUpdate()
464481
if process_returncode == 0:
@@ -741,35 +758,22 @@ def handleMcDisplayWeb(self):
741758
DISPLAY="mcdisplay"
742759
else:
743760
DISPLAY="mxdisplay"
744-
self.emitter.status('Running ' + DISPLAY + '-webgl...')
745-
try:
746-
cmd = DISPLAY+'-webgl --default -n100 ' + os.path.basename(self.state.getInstrumentFile()) + '&'
747-
self.emitter.message(cmd, gui=True)
748-
self.emitter.message('', gui=True)
749-
750-
def messg(s): self.emitter.message(s)
751-
def messg_err(s): self.emitter.message(s, err_msg=True)
752-
utils.run_subtool_to_completion(cmd, stdout_cb=messg, stderr_cb=messg_err)
753-
finally:
754-
self.emitter.status('')
755-
761+
tool=DISPLAY + "-webgl-classic"
762+
763+
self.emitter.status('Running ' + tool)
764+
self.state.vis_run(tool=tool)
765+
756766
def handleMcDisplay2D(self):
757767
if mccode_config.configuration["MCCODE"]=="mcstas":
758768
DISPLAY="mcdisplay"
759769
else:
760770
DISPLAY="mxdisplay"
761-
self.emitter.status('Running ' + DISPLAY + '-pyqtgraph...')
762-
try:
763-
cmd = DISPLAY+'-pyqtgraph --default -n100 ' + os.path.basename(self.state.getInstrumentFile()) + '&'
764-
self.emitter.message(cmd, gui=True)
765-
self.emitter.message('', gui=True)
766-
767-
def messg(s): self.emitter.message(s)
768-
def messg_err(s): self.emitter.message(s, err_msg=True)
769-
utils.run_subtool_to_completion(cmd, stdout_cb=messg, stderr_cb=messg_err)
770-
finally:
771-
self.emitter.status('')
772-
771+
tool=DISPLAY + "-pyqtgraph"
772+
773+
self.emitter.status('Running ' + tool)
774+
self.state.vis_run(tool=tool)
775+
776+
773777
def handleHelpWeb(self):
774778
# open the mcstas homepage
775779
mcurl = 'http://www.'+mccode_config.configuration["MCCODE"]+'.org'

tools/Python/mcgui/mw.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@
349349
</action>
350350
<action name="actionDisplay">
351351
<property name="text">
352-
<string>Display-3D</string>
352+
<string>Display-3D (classic)</string>
353353
</property>
354354
</action>
355355
<action name="actionDisplay_2d">

tools/Python/mcgui/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def retranslateUi(self, MainWindow):
263263
self.actionConfiguration.setToolTip(_translate("MainWindow", "mccode configuration"))
264264
self.actionCompile_Instrument_MPI.setText(_translate("MainWindow", "Compile Instrument (MPI)"))
265265
self.actionMcdoc.setText(_translate("MainWindow", "mcdoc Component Reference"))
266-
self.actionDisplay.setText(_translate("MainWindow", "Display-3D"))
266+
self.actionDisplay.setText(_translate("MainWindow", "Display-3D (classic)"))
267267
self.actionDisplay_2d.setText(_translate("MainWindow", "Display-2D"))
268268
self.actionPlotOther.setText(_translate("MainWindow", "Plot Other Results"))
269269
self.actionPlotOther.setShortcut(_translate("MainWindow", "Ctrl+Shift+P"))

0 commit comments

Comments
 (0)