Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
John Tourtellott
ACE3P Extensions
Commits
89e2ccf3
Commit
89e2ccf3
authored
Jan 16, 2020
by
John Tourtellott
Browse files
Add logic get path to CUBIT from user
parent
ff5ca570
Changes
2
Hide whitespace changes
Inline
Side-by-side
plugin/pqCubitToolBar.cxx
View file @
89e2ccf3
...
...
@@ -9,9 +9,23 @@
//=========================================================================
#include
"pqCubitToolBar.h"
// Client side
#include
"pqActiveObjects.h"
#include
"pqCoreUtilities.h"
#include
"pqServer.h"
#include
"vtkSMProperty.h"
#include
"vtkSMProxy.h"
#include
"vtkSMSessionProxyManager.h"
#include
"vtkSMStringVectorProperty.h"
// Qt
#include
<QAction>
#include
<QDebug>
#include
<QFileDialog>
#include
<QFileInfo>
#include
<QMessageBox>
#include
<QProcess>
#include
<QWidget>
pqCubitToolBar
::
pqCubitToolBar
(
QWidget
*
parent
)
:
Superclass
(
"CUBIT Application"
,
parent
)
...
...
@@ -26,5 +40,131 @@ pqCubitToolBar::~pqCubitToolBar() = default;
void
pqCubitToolBar
::
onLaunch
()
{
QMessageBox
::
information
(
this
,
""
,
"Todo Launch CUBIT"
);
// Get the CUBIT path from application settings
QWidget
*
mainWidget
=
pqCoreUtilities
::
mainWidget
();
pqServer
*
server
=
pqActiveObjects
::
instance
().
activeServer
();
vtkSMProxy
*
proxy
=
server
->
proxyManager
()
->
GetProxy
(
"settings"
,
"ACE3PSettings"
);
if
(
!
proxy
)
{
QMessageBox
::
warning
(
mainWidget
,
"Internal Error"
,
"Internal Error: Settings proxy for ACE3P not found."
);
return
;
}
vtkSMProperty
*
cubitProp
=
proxy
->
GetProperty
(
"CubitPath"
);
auto
*
cubitStringProp
=
vtkSMStringVectorProperty
::
SafeDownCast
(
cubitProp
);
if
(
!
cubitStringProp
)
{
QMessageBox
::
warning
(
mainWidget
,
"Internal Error"
,
"Internal Error: CubitPath not found in ACE3P settings."
);
return
;
}
std
::
string
cubitPath
=
cubitStringProp
->
GetElement
(
0
);
// Make sure the path is set to a valid executable
bool
done
=
false
;
QString
path
=
QString
::
fromStdString
(
cubitPath
);
int
ret
;
while
(
!
done
)
{
QString
headline
;
QString
details
;
if
(
path
.
isEmpty
())
{
headline
=
"The application does not know where CUBIT is on your system."
;
details
=
"Do you want to set it now?"
;
this
->
askUserForPath
(
headline
,
details
,
path
);
if
(
path
.
isEmpty
())
{
break
;
}
}
// if (path empty)
// Check path
QString
reason
;
if
(
this
->
checkPath
(
path
,
reason
))
{
done
=
true
;
break
;
}
// (else)
this
->
askUserForPath
(
reason
,
"Do you want to try again?"
,
path
);
if
(
path
.
isEmpty
())
{
break
;
}
}
// while
if
(
path
.
isEmpty
())
{
return
;
}
// (else)
cubitPath
=
path
.
toStdString
();
// Update settings
cubitStringProp
->
SetElement
(
0
,
cubitPath
.
c_str
());
proxy
->
UpdateVTKObjects
();
// Run the process
// return this->runCubit(cubit_path);
QMessageBox
::
information
(
mainWidget
,
"CUBIT PATH FOUND"
,
path
);
}
void
pqCubitToolBar
::
askUserForPath
(
const
QString
&
headline
,
const
QString
&
details
,
QString
&
result
)
const
{
QWidget
*
mainWidget
=
pqCoreUtilities
::
mainWidget
();
QMessageBox
msgBox
(
mainWidget
);
msgBox
.
setText
(
headline
);
msgBox
.
setInformativeText
(
details
);
msgBox
.
setStandardButtons
(
QMessageBox
::
No
|
QMessageBox
::
Yes
);
msgBox
.
setDefaultButton
(
QMessageBox
::
Yes
);
int
msgRet
=
msgBox
.
exec
();
if
(
msgRet
!=
QMessageBox
::
Yes
)
{
result
.
clear
();
return
;
}
QFileDialog
fileDialog
(
mainWidget
,
"CUBIT executable"
);
fileDialog
.
setAcceptMode
(
QFileDialog
::
AcceptOpen
);
fileDialog
.
setFileMode
(
QFileDialog
::
ExistingFile
);
bool
fileRet
=
fileDialog
.
exec
();
if
(
fileRet
!=
QDialog
::
Accepted
)
{
result
.
clear
();
}
else
{
result
=
fileDialog
.
selectedFiles
().
at
(
0
);
}
}
bool
pqCubitToolBar
::
checkPath
(
const
QString
&
path
,
QString
&
reason
)
const
{
QFileInfo
fileInfo
(
path
);
if
(
!
fileInfo
.
exists
())
{
reason
=
"File was not found at "
+
path
+
"."
;
return
false
;
}
if
(
!
fileInfo
.
isExecutable
())
{
reason
=
"The file is not executable: "
+
path
+
"."
;
return
false
;
}
if
(
!
fileInfo
.
permission
(
QFileDevice
::
ExeUser
))
{
reason
=
"The current user does not have permission to run "
+
path
+
"."
;
return
false
;
}
return
true
;
}
plugin/pqCubitToolBar.h
View file @
89e2ccf3
...
...
@@ -27,6 +27,9 @@ public:
pqCubitToolBar
(
QWidget
*
parent
=
nullptr
);
~
pqCubitToolBar
()
override
;
protected:
void
askUserForPath
(
const
QString
&
headline
,
const
QString
&
details
,
QString
&
result
)
const
;
bool
checkPath
(
const
QString
&
path
,
QString
&
reason
)
const
;
protected
slots
:
void
onLaunch
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment