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
Add egs_editor support for transformations
  • Loading branch information
rtownson committed Sep 17, 2024
commit d6fca0769a93b8f84c433ec2400265024b06efd8
29 changes: 23 additions & 6 deletions HEN_HOUSE/egs++/egs_input_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ void EGS_InputStruct::addBlockInputs(vector<shared_ptr<EGS_BlockInput>> blocks)
blockInputs.insert(blockInputs.end(), blocks.begin(), blocks.end());
}

shared_ptr<EGS_BlockInput> EGS_InputStruct::addFloatingBlock(shared_ptr<EGS_BlockInput> block) {
floatingBlocks.push_back(block);

return floatingBlocks.back();
}

vector<shared_ptr<EGS_BlockInput>> EGS_InputStruct::getBlockInputs() {
return blockInputs;
}
Expand Down Expand Up @@ -111,6 +105,23 @@ vector<string> EGS_InputStruct::getLibraryOptions(string blockTitle) {
}
}
}

// If nothing was found on the 2nd level blocks, search the top level ones
// This is the case for shapes
if(libOptions.size() < 1) {
for(auto& block : blockInputs) {
egsInformation("test getLibOpt2 %s %s\n",block->getTitle().c_str(),blockTitle.c_str() );
if(block && block->getTitle() == blockTitle) {
vector<string> libAr = block->getSingleInput("library")->getValues();
for(auto& lib : libAr) {
if(lib.size() > 0) {
libOptions.push_back(lib);
}
}
}
}
}

return libOptions;
}

Expand Down Expand Up @@ -236,6 +247,12 @@ shared_ptr<EGS_BlockInput> EGS_BlockInput::getBlockInput(string title) {
for(auto &block: blockInputs) {
if(egsEquivStr(block->getTitle(), title)) {
return block;
} else {
// Do a recursive search
auto foundBlock = block->getBlockInput(title);
if(foundBlock) {
return foundBlock;
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions HEN_HOUSE/egs++/egs_input_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ class EGS_EXPORT EGS_InputStruct {
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);
shared_ptr<EGS_BlockInput> addFloatingBlock(shared_ptr<EGS_BlockInput> block);
vector<shared_ptr<EGS_BlockInput>> getBlockInputs();
shared_ptr<EGS_BlockInput> getBlockInput(string title);
shared_ptr<EGS_BlockInput> getLibraryBlock(string blockTitle, string libraryName);
Expand All @@ -142,7 +141,7 @@ class EGS_EXPORT EGS_InputStruct {
private:

vector<shared_ptr<EGS_BlockInput>> blockInputs;
vector<shared_ptr<EGS_BlockInput>> floatingBlocks;
vector<shared_ptr<EGS_BlockInput>> generalBlocks;
};


Expand Down
2 changes: 2 additions & 0 deletions HEN_HOUSE/egs++/egs_shapes.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ static void setShapeInputs(shared_ptr<EGS_BlockInput> shapePtr) {
shapePtr->addSingleInput("height", false, "The height of the cylinder, in cm.")->addDependency(typePtr, "cylinder");
shapePtr->addSingleInput("phi range", false, "The minimum and maximum phi values, in degrees. This allows you restrict the cylinder to a shape like a slice of pie!")->addDependency(typePtr, "cylinder");
shapePtr->addSingleInput("axis", false, "A unit vector that defines the axis of the cylinder.")->addDependency(typePtr, "cylinder");

addTransformationBlock(shapePtr);
}

/*! \defgroup Shapes Shapes
Expand Down
10 changes: 10 additions & 0 deletions HEN_HOUSE/egs++/egs_transformations.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,23 @@
#include "egs_libconfig.h"
#include "egs_math.h"
#include "egs_functions.h"
#include "egs_input_struct.h"

#include <iostream>

using namespace std;

class EGS_Input;

static void addTransformationBlock(shared_ptr<EGS_BlockInput> blockPtr) {
shared_ptr<EGS_BlockInput> transBlock = blockPtr->addBlockInput("transformation");
transBlock->addSingleInput("translation", false, "The x, y, z translation offsets in cm.");
auto vecPtr = transBlock->addSingleInput("rotation vector", false, "Defines a rotation which, when applied to the 3D vector defined by this input, transforms it into a vector along the positive z-axis.");
auto rotPtr = transBlock->addSingleInput("rotation", false, "2, 3 or 9 floating point numbers define a rotation. See the documentation for details.");
vecPtr->addDependency(rotPtr, "", true);
rotPtr->addDependency(vecPtr, "", true);
}

/*! \brief A class for vector rotations.

\ingroup egspp_main
Expand Down
58 changes: 50 additions & 8 deletions HEN_HOUSE/egs++/view/egs_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,19 +457,21 @@ void EGS_Editor::autoComplete() {

vector<shared_ptr<EGS_BlockInput>> blockInputs = inputBlockTemplate->getBlockInputs(blockTitle.toStdString());

//vector<shared_ptr<EGS_BlockInput>> generalInputs = inputBlockTemplate->getGeneralBlock(blockTitle.toStdString());

// Populate the popup list
QStringList itemList;

// Add all the single inputs for the top level block
for(auto &inp: singleInputs) {
if(!egsEquivStr(inp->getTag(), "library")) {
//if(!egsEquivStr(inp->getTag(), "library")) {
// Skip any inputs that have a dependency which is not satisfied
if(inputHasDependency(inp) && inputDependencySatisfied(inp, cursor) == false) {
continue;
}

itemList << QString((inp->getTag() + " = ").c_str());
}
//}
}

// Store the block titles in a set to remove duplicates
Expand Down Expand Up @@ -543,6 +545,7 @@ void EGS_Editor::autoComplete() {
QTextCharFormat format;
format.setUnderlineStyle(QTextCharFormat::NoUnderline);

egsInformation("testQQ %s %s\n",blockTit.toLatin1().data(), selectedText.toLatin1().data());
auto inputPtr = inputBlockTemplate->getBlockInput(blockTit.toStdString());
if(!inputPtr) {
// Red underline the input tag
Expand Down Expand Up @@ -635,14 +638,25 @@ shared_ptr<EGS_BlockInput> EGS_Editor::getBlockInput(QString &blockTitle, QTextC
// If we couldn't find a library tag in the current block,
// try searching the containing block (if there is one)
if(library.size() < 1) {
// If we're current on a :start line, start searching on the next line
egsInformation("test searching containing block %s\n", blockTitle.toLatin1().data());

// If we're currently on a :start line, start searching on the next line
// so that we're actually starting within the block
QTextBlock blockEnd;
if(cursor.block().text().contains(":start ")) {
blockEnd = getBlockEnd(cursor.block().next());
} else {
blockEnd = getBlockEnd(cursor.block());
blockEnd = cursor.block();
int loopGuard = 10000;
int i = 0;
while(blockEnd.text().contains(":start ")) {
blockEnd = getBlockEnd(blockEnd.next());
if(++i > loopGuard) {
egsInformation("Warning: Encountered infinite loop while processing the input file. Contact the developers to report this bug.\n");
break;
}
if(blockEnd.isValid()) {
blockEnd = blockEnd.next();
}
}
blockEnd = getBlockEnd(blockEnd);
if(!blockEnd.isValid()) {
return nullptr;
}
Expand All @@ -652,7 +666,35 @@ shared_ptr<EGS_BlockInput> EGS_Editor::getBlockInput(QString &blockTitle, QTextC

// Check for the library tag here
library = getInputValue("library", blockEnd, foundTag);
egsInformation("test searching containing block %s\n", library.toLatin1().data());

// If we still didn't find the library, search one block higher
if(library.size() < 1) {
egsInformation("test searching containing block2 %s\n", blockTitle.toLatin1().data());
// If we're currently on a :start line, start searching on the next line
// so that we're actually starting within the block
int loopGuard = 10000;
int i = 0;
while(blockEnd.text().contains(":start ")) {
blockEnd = getBlockEnd(blockEnd.next());
if(++i > loopGuard) {
egsInformation("Warning: Encountered infinite loop while processing the input file. Contact the developers to report this bug.\n");
break;
}
if(blockEnd.isValid()) {
blockEnd = blockEnd.next();
}
}
blockEnd = getBlockEnd(blockEnd);
if(!blockEnd.isValid()) {
return nullptr;
}

// Go to the line after the end of the current input block
blockEnd = blockEnd.next();

// Check for the library tag here
library = getInputValue("library", blockEnd, foundTag);
}
}

// If we got the library tag, we can directly look up this input block structure
Expand Down
5 changes: 4 additions & 1 deletion HEN_HOUSE/egs++/view/viewcontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ GeometryViewControl::GeometryViewControl(QWidget *parent, const char *name)
continue;
}

// Geometries
createGeomFunction isGeom = (createGeomFunction) egs_lib.resolve("createGeometry");
if (isGeom) {
egsInformation(" testgeom %s\n",libName.toLatin1().data());
Expand Down Expand Up @@ -330,6 +331,7 @@ GeometryViewControl::GeometryViewControl(QWidget *parent, const char *name)
}
}

// Sources
createSourceFunction isSource = (createSourceFunction) egs_lib.resolve("createSource");
if (isSource) {
egsInformation(" testsrc %s\n",libName.toLatin1().data());
Expand Down Expand Up @@ -373,6 +375,7 @@ GeometryViewControl::GeometryViewControl(QWidget *parent, const char *name)
}
}

// Shapes
createShapeFunction isShape = (createShapeFunction) egs_lib.resolve("createShape");
if (isShape) {
egsInformation(" testshape %s\n",libName.toLatin1().data());
Expand All @@ -382,7 +385,7 @@ GeometryViewControl::GeometryViewControl(QWidget *parent, const char *name)

shared_ptr<EGS_BlockInput> shape = getInputs();
if (shape) {
inputStruct->addFloatingBlock(shape);
inputStruct->addBlockInput(shape);

vector<shared_ptr<EGS_SingleInput>> singleInputs = shape->getSingleInputs();
for (auto &inp : singleInputs) {
Expand Down