Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
69 changes: 69 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,32 @@
nativeBuildInputs = old.nativeBuildInputs ++ [
prev.libsForQt5.wrapQtAppsHook
];
prePatch = let
icon = lib.nix-filter {
root = ./.;
include = [
"icon"
];
};
in ''
# Allow to open .csx files
substituteInPlace QCSXCAD.cpp --replace-fail 'XML-File (*.xml)' 'XML-File (*.xml *.csx)'

# Open OEMSH
cp ${icon}/icon/openemsh.ico images/openemsh.ico
sed -i resources.qrc \
-e '/^ <file>images\/QCSXCAD_Icon.png<\/file>/a\ <file>images\/openemsh.ico<\/file>'
sed -i QCSGridEditor.h \
-e '/^ void DetectEdges();/a\ void RunOpenEMSH();' \
-e '/^ void signalDetectEdges(int);/a\ void signalRunOpenEMSH();'
sed -i QCSGridEditor.cpp \
-e '/^ TB->addAction(tr("detect \\nedges"),this,SLOT(DetectEdges()));/a\ TB->addAction(QPixmap(":\/images\/openemsh.ico"),tr("Run OpenEMSH"),this,SLOT(RunOpenEMSH()));' \
-e '/^void QCSGridEditor::BuildHomogenDisc()/i\void QCSGridEditor::RunOpenEMSH() { emit signalRunOpenEMSH(); }'
sed -i QCSXCAD.h \
-e '/^ virtual void clear();/i\ virtual void RunOpenEMSH() {}'
sed -i QCSXCAD.cpp \
-e '/^ QObject::connect(GridEditor,SIGNAL(signalDetectEdges(int)),this,SLOT(DetectEdges(int)));/a\ QObject::connect(GridEditor,SIGNAL(signalRunOpenEMSH()),this,SLOT(RunOpenEMSH()));'
'';
})).override {
mkDerivation = prev.fastStdenv.mkDerivation;
inherit (final) csxcad;
Expand All @@ -247,6 +273,49 @@
nativeBuildInputs = old.nativeBuildInputs ++ [
prev.libsForQt5.wrapQtAppsHook
];
prePatch = let
run_oemsh = ''
void AppCSXCAD::RunOpenEMSH()
{
if(bModified) {
if(QMessageBox::question(this, tr("OpenEMSH mesher"), tr("Save current Geometry before meshing? (only geometry matters, mesh will be overwritten)"), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes) == QMessageBox::Yes) {
Save();
bModified=false;
}
}

setEnabled(false);
repaint();
QGuiApplication::setOverrideCursor(QCursor(Qt::ForbiddenCursor));
int ret = QProcess::execute("openemsh", { "-Gvf", "--input", m_filename });
QGuiApplication::restoreOverrideCursor();
setEnabled(true);

if(ret == -1) {
QMessageBox::warning(this, tr("OpenEMSH mesher"), tr("Error OpenEMSH crashed!"));
} else if(ret == -2) {
QMessageBox::warning(this, tr("OpenEMSH mesher"), tr("Error OpenEMSH could not start!"));
} else {
ReadFile(m_filename);
}
}
'';
in ''
# Set icon
# TODO add Windows RC file
sed -i AppCSXCAD.cpp \
-e '/^ QString title = tr("AppCSXCAD");/a\ setWindowIcon(QPixmap(":/images/QCSXCAD_Icon.png"));'

# Open OEMSH
sed -i AppCSXCAD.h \
-e '/^ virtual void clear();/a\void RunOpenEMSH() override;'
sed -i AppCSXCAD.cpp \
-e '/^QMenu *InfoMenu = mb->addMenu("Info");/a\ QObject::connect(this, QCSXCAD::signalRunOpenEMSH, this, AppCSXCAD::RunOpenEMSH);' \
-e 's/ return QCSXCAD::ReadFile(filename);/ bool ret = QCSXCAD::ReadFile(filename);\n bModified = false;\n return ret;/'
cat >> AppCSXCAD.cpp << EOF
${run_oemsh}
EOF
'';
})).override {
mkDerivation = prev.fastStdenv.mkDerivation;
inherit (final) csxcad qcsxcad;
Expand Down
Binary file added icon/qcsxcad.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 17 additions & 5 deletions src/infra/parsers/parser_from_csx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,20 +673,32 @@ expected<void, string> ParserFromCsx::parse() {
TRY(pimpl->parse_oemsh(oemsh.node()));
}

if(!doc.select_node("/openEMS"))
bool is_under_openems;
if(doc.select_node("/openEMS/ContinuousStructure"))
is_under_openems = true;
else if(doc.select_node("/ContinuousStructure"))
is_under_openems = false;
else
return unexpected("No \"/openEMS\" path in CSX XML file");

pugi::xpath_node fdtd = doc.select_node("/openEMS/FDTD");
auto const root = [&](string const str) {
if(is_under_openems)
return "/openEMS"s + str;
else
return str;
};

pugi::xpath_node fdtd = doc.select_node(root("/FDTD").c_str());

pugi::xpath_node csx = doc.select_node("/openEMS/ContinuousStructure");
pugi::xpath_node csx = doc.select_node(root("/ContinuousStructure").c_str());
TRY(pimpl->parse_grid(csx.node()));

pimpl->board.set_background_material(pimpl->parse_property(csx.node().child("BackgroundMaterial")));

{
// Primitives' IDs grow disregarding properties.
size_t id = 0;
pugi::xpath_node_set primitives = doc.select_nodes("/openEMS/ContinuousStructure/Properties/*/Primitives");
pugi::xpath_node_set primitives = doc.select_nodes(root("/ContinuousStructure/Properties/*/Primitives").c_str());
for(auto const& primitive : primitives)
for(auto const& node : primitive.node().children()) {
pimpl->primitives_ids.emplace(node, id++);
Expand All @@ -698,7 +710,7 @@ expected<void, string> ParserFromCsx::parse() {
pimpl->primitives_ids.size(),
"Parsing primitives ");

pugi::xpath_node properties = doc.select_node("/openEMS/ContinuousStructure/Properties");
pugi::xpath_node properties = doc.select_node(root("/ContinuousStructure/Properties").c_str());
for(auto const& node : properties.node().children()) {
auto material = pimpl->parse_property(node);

Expand Down
9 changes: 7 additions & 2 deletions src/infra/serializers/serializer_to_csx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,13 @@ void SerializerToCsx::visit(Board& board) {
return;
}

pugi::xml_node oems = find_or_append_child(doc, "openEMS");
pugi::xml_node csx = find_or_append_child(oems, "ContinuousStructure");
pugi::xml_node csx;
if(doc.select_node("/ContinuousStructure")) {
csx = find_or_append_child(doc, "ContinuousStructure");
} else {
pugi::xml_node oems = find_or_append_child(doc, "openEMS");
csx = find_or_append_child(oems, "ContinuousStructure");
}
pugi::xml_node grid = find_or_append_child(csx, "RectilinearGrid");
grid.remove_children();

Expand Down
Loading
Loading