Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add egs_view egsinp editor with autocompletion for all egs++ apps #1164

Draft
wants to merge 40 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5cf74da
Add a text editor to egs_view
rtownson Aug 3, 2019
439a0dc
Non-working temporary commit
rtownson Dec 13, 2019
1caf68c
Add a text editor to egs_view
rtownson Aug 3, 2019
0d03724
Non-working temporary commit
rtownson Dec 13, 2019
5642956
Add editor autocomplete and input checking
rtownson Feb 4, 2020
19922d9
Improve egs_view editor input checking
rtownson Feb 22, 2020
212a9f2
Add egs_view editor input dependency checking
rtownson Mar 13, 2020
b7da362
Start adding egs_view editor definition blocks
rtownson Mar 13, 2020
618c6f0
Add egs_view editor source and shape support
rtownson Mar 31, 2020
406f174
Add egs_editor input example menu bar
rtownson Apr 3, 2020
31d2374
Temp
rtownson May 13, 2020
d6fca07
Add egs_editor support for transformations
rtownson Jul 7, 2020
916f1f0
Start adding egs_editor run control support
rtownson Jul 20, 2020
e320166
Finish adding run control inputs to egs_editor
rtownson Jul 23, 2020
85326e6
Improve egs_editor undo history
rtownson Jul 30, 2020
4d2895c
Add Geometry Input Validation
Feb 2, 2021
1d65c15
Add sources, ausgab, other egs_view editor support
hcgallop Feb 10, 2021
0f59cd3
Add support for shapes in egs_view editor
hcgallop Feb 15, 2021
790ed98
Add keystroke seletion to egs_editor
hcgallop Feb 26, 2021
dbcec3a
Add support for applications in egs_view editor
hcgallop Apr 26, 2021
ea05f21
Add support for red line comments
hcgallop Apr 30, 2021
ecd69e2
Fix the recent egs_view ui changes
May 19, 2021
81a28e4
Fix the egs_view dso link to be a relative path
rtownson May 20, 2021
99b8ef4
Add iaea_phsp_source editor inputs
rtownson Apr 6, 2022
2a2e604
Remove old egs_view debug messages
rtownson Apr 7, 2022
70be98a
Improve egs_editor support for shapes
rtownson May 2, 2022
c8c35a9
Run astyle to fix formatting
rtownson May 10, 2022
c78965f
Fix a few typos in the egs_editor additions
rtownson Jun 28, 2022
868f84c
Update egs_input_struct documentation
rtownson Jul 4, 2022
85a78cf
Tidy up egs_view debug output
rtownson Jul 5, 2022
9549983
Fix egs_view image scaling when reloading or saving
rtownson Nov 9, 2023
be3fe92
Add the library auto complete for ausgab objects
rtownson Nov 9, 2023
d251483
Add more egs_editor completion and examples
Xuan-Zheng05 Jul 26, 2024
a45213c
Fixed hardcoded path to density correction files with system dependen…
Xuan-Zheng05 Aug 10, 2024
56e1cce
Fix pegless material autocompletion to work with any name
Xuan-Zheng05 Aug 14, 2024
d2b97b9
Fix incorrect example for media definition
Xuan-Zheng05 Aug 22, 2024
a509ab2
Fix autocomplete error from pegless material addition
Xuan-Zheng05 Aug 30, 2024
efcfc4d
Fix egs_editor medium autocomplete
rtownson Aug 8, 2024
59ea112
Fix make clean of application library objects
rtownson Aug 8, 2024
99e2cbb
Tidy up merge with branch from Xuan
rtownson Sep 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Start adding egs_view editor definition blocks
  • Loading branch information
rtownson committed Sep 17, 2024
commit b7da362269eddc830bfc900e5f3d08dc629b749d
1 change: 1 addition & 0 deletions HEN_HOUSE/egs++/egs_base_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class label {

static shared_ptr<EGS_BlockInput> blockInput = make_shared<EGS_BlockInput>("geometry");
static void setBaseGeometryInputs(bool includeMediaBlock = true) {
blockInput->addSingleInput("library", true, "The type of geometry, loaded by shared library in egs++/dso.");
blockInput->addSingleInput("name", true, "The user-declared unique name of this geometry. This is the name you may refer to elsewhere in the input file");

if(includeMediaBlock) {
Expand Down
29 changes: 28 additions & 1 deletion HEN_HOUSE/egs++/egs_input_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ EGS_InputStruct::EGS_InputStruct() {}

EGS_InputStruct::~EGS_InputStruct() {}

void EGS_InputStruct::addBlockInput(shared_ptr<EGS_BlockInput> block) {
shared_ptr<EGS_BlockInput> EGS_InputStruct::addBlockInput(string blockTit, bool isReq) {
blockInputs.push_back(make_shared<EGS_BlockInput>(blockTit, isReq, nullptr));

return blockInputs.back();
}

shared_ptr<EGS_BlockInput> EGS_InputStruct::addBlockInput(shared_ptr<EGS_BlockInput> block) {
blockInputs.push_back(block);
}

Expand All @@ -54,6 +60,16 @@ vector<shared_ptr<EGS_BlockInput>> EGS_InputStruct::getBlockInputs() {
return blockInputs;
}

shared_ptr<EGS_BlockInput> EGS_InputStruct::getBlockInput(string title) {
for(auto &block: blockInputs) {
if(egsEquivStr(block->getTitle(), title)) {
return block;
}
}

return nullptr;
}

shared_ptr<EGS_BlockInput> EGS_InputStruct::getLibraryBlock(string blockTitle, string libraryName) {
// Loop through each input block in the structure to find the library with
// the matching name
Expand Down Expand Up @@ -112,6 +128,13 @@ shared_ptr<EGS_BlockInput> EGS_BlockInput::addBlockInput(string blockTit, bool i
return blockInputs.back();
}

shared_ptr<EGS_BlockInput> EGS_BlockInput::addBlockInput(shared_ptr<EGS_BlockInput> block) {
block->setParent(shared_from_this());
blockInputs.push_back(block);

return blockInputs.back();
}

vector<shared_ptr<EGS_SingleInput>> EGS_BlockInput::getSingleInputs() {
return singleInputs;
}
Expand Down Expand Up @@ -299,6 +322,10 @@ const vector<string> EGS_SingleInput::getValues() {
return values;
}

void EGS_SingleInput::setValues(const vector<string> vals) {
values = vals;
}

string EGS_SingleInput::getDescription() {
return description;
}
Expand Down
11 changes: 7 additions & 4 deletions HEN_HOUSE/egs++/egs_input_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,13 @@ class EGS_EXPORT EGS_SingleInput {

string getTag();
bool getRequired();
const vector<string> getValues();
string getDescription();
void addDependency(shared_ptr<EGS_SingleInput> inp, string val="", bool isAntiDependency = false);
vector<shared_ptr<EGS_SingleInput>> getDependencyInp();
vector<string> getDependencyVal();
vector<bool> getDependencyAnti();
const vector<string> getValues();
void setValues(const vector<string> vals);
string getDescription();

private:

Expand All @@ -88,6 +89,7 @@ class EGS_EXPORT EGS_BlockInput
string getTitle();
shared_ptr<EGS_SingleInput> addSingleInput(string inputTag, bool isReq, const string desc, const vector<string> vals = vector<string>());
shared_ptr<EGS_BlockInput> addBlockInput(string blockTit, bool isReq = false);
shared_ptr<EGS_BlockInput> addBlockInput(shared_ptr<EGS_BlockInput> block);
vector<shared_ptr<EGS_SingleInput>> getSingleInputs();
vector<shared_ptr<EGS_SingleInput>> getSingleInputs(string title);
vector<shared_ptr<EGS_BlockInput>> getBlockInputs();
Expand Down Expand Up @@ -121,10 +123,11 @@ class EGS_EXPORT EGS_InputStruct {
EGS_InputStruct();
~EGS_InputStruct();

void addBlockInput(shared_ptr<EGS_BlockInput> block);
//void addBlockInput(string blockTit, bool isReq);
shared_ptr<EGS_BlockInput> addBlockInput(string blockTit, bool isReq = false);
shared_ptr<EGS_BlockInput> addBlockInput(shared_ptr<EGS_BlockInput> block);
void addBlockInputs(vector<shared_ptr<EGS_BlockInput>> blocks);
vector<shared_ptr<EGS_BlockInput>> getBlockInputs();
shared_ptr<EGS_BlockInput> getBlockInput(string title);
shared_ptr<EGS_BlockInput> getLibraryBlock(string blockTitle, string libraryName);
vector<string> getLibraryOptions(string blockTitle);

Expand Down
3 changes: 2 additions & 1 deletion HEN_HOUSE/egs++/geometry/egs_box/egs_box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ extern "C" {

setBaseGeometryInputs();

blockInput->getSingleInput("library")->setValues(vector<string>(1, typeStr));

// Format: name, isRequired, description, vector string of allowed values
blockInput->addSingleInput("library", true, "The type of geometry, loaded by shared library in egs++/dso.", vector<string>(1, typeStr));
blockInput->addSingleInput("box size", true, "1 number defining the side-length of a cube, or 3 numbers defining the x, y, and z side-lengths.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ extern "C" {

setBaseGeometryInputs(false);

// Format: name, isRequired, description, vector string of allowed values
blockInput->addSingleInput("library", true, "The type of geometry, loaded by shared library in egs++/dso.", vector<string>(1, typeStr));
blockInput->getSingleInput("library")->setValues(vector<string>(1, typeStr));

// Format: name, isRequired, description, vector string of allowed values
blockInput->addSingleInput("base geometry", true, "The name of the geometry that defines regions for this 'cutting device'. It is within these regions that other geometries will be placed to create a composite geometry.");
blockInput->addSingleInput("set geometry", true, "The region number in the base geometry, followed by the name of the geometry to place in that region. If this geometry extends beyond the region boundaries, it will be cut to size.");
blockInput->addSingleInput("new indexing style", false, "Set to 1 to use a new region numbering algorithm. Defaults to 0, to use the original indexing style.");
Expand Down
3 changes: 2 additions & 1 deletion HEN_HOUSE/egs++/geometry/egs_cones/egs_cones.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,9 @@ extern "C" {

setBaseGeometryInputs(false);

blockInput->getSingleInput("library")->setValues({"EGS_Cones"});

// Format: name, isRequired, description, vector string of allowed values
blockInput->addSingleInput("library", true, "The type of geometry, loaded by shared library in egs++/dso.", {"EGS_Cones"});
auto typePtr = blockInput->addSingleInput("type", true, "The type of cone.", {"EGS_ConeStack", "EGS_SimpleCone", "EGS_ParallelCones", "EGS_ConeSet"});

blockInput->addSingleInput("axis", false, "The unit vector defining the axis along the length of the cones. Layers or cones are added sequentially in the vector direction.");
Expand Down
61 changes: 56 additions & 5 deletions HEN_HOUSE/egs++/view/egs_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,14 @@ void EGS_Editor::autoComplete() {
itemList << QString((inp->getTag() + " = ").c_str());
}
}

// Store the block titles in a set to remove duplicates
QSet<QString> blockTitles;
for(auto &block: blockInputs) {
itemList << QString((":start " + block->getTitle() + ":").c_str());
blockTitles << QString((":start " + block->getTitle() + ":").c_str());
}
for(auto &title: blockTitles) {
itemList << title;
}
if(itemList.size() > 0) {
model->setStringList(itemList);
Expand Down Expand Up @@ -416,12 +422,12 @@ void EGS_Editor::autoComplete() {
if(inputBlockTemplate) {

// Get the block title
QString blockTitle;
QString blockTit;
int pos = selectedText.lastIndexOf(":start ");
pos += 7;
int endPos = selectedText.indexOf(":",pos);
if(endPos > 0) {
blockTitle = selectedText.mid(pos, endPos-pos);
blockTit = selectedText.mid(pos, endPos-pos);
}

QList<QTextEdit::ExtraSelection> extraSelections = this->extraSelections();
Expand All @@ -437,7 +443,7 @@ void EGS_Editor::autoComplete() {
QTextCharFormat format;
format.setUnderlineStyle(QTextCharFormat::NoUnderline);

auto inputPtr = inputBlockTemplate->getBlockInput(blockTitle.toStdString());
auto inputPtr = inputBlockTemplate->getBlockInput(blockTit.toStdString());
if(!inputPtr) {
// Red underline the input tag
// Select the input tag
Expand All @@ -464,6 +470,47 @@ void EGS_Editor::autoComplete() {
extraSelections.append(selection);
setExtraSelections(extraSelections);
}

// For geometry and source blocks that don't contain a library line,
// add 'library =' as an option in the popup
} else if(egsEquivStr(blockTitle, "geometry")) {

// Populate the popup list
QStringList itemList;
itemList << "library";
if(itemList.size() > 0) {
model->setStringList(itemList);
}

popup->setModel(model);
popup->setFont(this->font());

// Get max string length
int strLength = 0;
for (auto &item: itemList) {
if (item.size() > strLength) {
strLength = item.size();
}
}

// Create a selection popup
int maxVisibleItems = 6;
int h = (popup->sizeHintForRow(0) * qMin(maxVisibleItems, popup->model()->rowCount()) + 3) + 3;
QScrollBar *hsb = popup->horizontalScrollBar();
if (hsb && hsb->isVisible()) {
h += popup->horizontalScrollBar()->sizeHint().height();
}

QPoint pos = this->viewport()->mapToGlobal(this->cursorRect().bottomRight());
QFontMetrics fm(popup->font());
int w = 20 + strLength * fm.horizontalAdvance('9');

popup->setGeometry(pos.x(), pos.y(), w, h);

// Show the popup
if (!popup->isVisible()) {
popup->show();
}
}
}

Expand Down Expand Up @@ -512,7 +559,11 @@ shared_ptr<EGS_BlockInput> EGS_Editor::getBlockInput(QString &blockTitle) {
}
}

return nullptr;
// If we didn't get the library tag, we might be in a top-level block
// like a geometry definition. Just return the block with the matching title
shared_ptr<EGS_BlockInput> inputBlock = inputStruct->getBlockInput(blockTitle.toStdString());

return inputBlock;
}

QString EGS_Editor::getBlockTitle() {
Expand Down
14 changes: 11 additions & 3 deletions HEN_HOUSE/egs++/view/viewcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,16 @@ GeometryViewControl::GeometryViewControl(QWidget *parent, const char *name)
QStringList libraries = directory.entryList(QStringList() << (lib_prefix+"*"+lib_suffix).c_str(), QDir::Files);
QStringList geomLibs, sourceLibs;

shared_ptr<EGS_InputStruct> inputStruct(new EGS_InputStruct);
// The input template structure
inputStruct = make_shared<EGS_InputStruct>();

// Geometry definition block
auto geomDefPtr = inputStruct->addBlockInput("geometry definition");
geomDefPtr->addSingleInput("simulation geometry", true, "The name of the geometry that will be used in the simulation, or to be viewed in egs_view. If you have created a composite geometry using many other geometries, name the final composite geometry here. Note that in some applications, the calculation geometry input block overrides this input, but it is still required.");

// Source definition block
auto srcDefPtr = inputStruct->addBlockInput("source definition");
srcDefPtr->addSingleInput("simulation source", true, "The name of the source that will be used in the simulation. If you have created a composite source using many other sources, name the final composite source here.");

// For each library, try to load it and determine if it is geometry or source
for (const auto &lib : libraries) {
Expand All @@ -273,7 +282,7 @@ GeometryViewControl::GeometryViewControl(QWidget *parent, const char *name)

shared_ptr<EGS_BlockInput> geom = getInputs();
if (geom) {
geomTemplates.push_back(geom);
geomDefPtr->addBlockInput(geom);

vector<shared_ptr<EGS_SingleInput>> singleInputs = geom->getSingleInputs();
for (auto &inp : singleInputs) {
Expand Down Expand Up @@ -315,7 +324,6 @@ GeometryViewControl::GeometryViewControl(QWidget *parent, const char *name)
}
}

inputStruct->addBlockInputs(geomTemplates);
egsinpEdit->setInputStruct(inputStruct);

// Populate the geometry and simulation template lists
Expand Down