mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2026-10-10 22:24:13 +02:00
Add a generic device: a box symbol with terminals on any side
Edit > Add > Generic device (also on the Add toolbar, and found by the
command search as diagrameditor.add_generic_device) opens a three-page
wizard for devices used too rarely to draw a symbol for, such as a VSD
or a power supply:
1. Layout: terminals per side (0 for none), a gap every N terminals,
divider marks on gaps, groups lined up across opposite sides, pitch
and extra size.
2. Terminals: a table per side and the same list as one line, where
In{4} is In1..In4, Q{z4} is Q0..Q3, X{3-6} is X3..X6 and an empty
entry is a gap; number pins 1..n counter-clockwise; paste rows of
side, name, function from a spreadsheet or a CSV file.
3. Information: name, label, manufacturer, reference, description.
A preview beside every page shows the box as it will be placed. Finish,
available from the first page, writes an ordinary symbol to the folder
"Generic devices" of the project's collection and puts it on the cursor.
The box sizes itself to its terminals and their names; every terminal
lands on the grid and gets a uuid. No new XML: any QElectroTech reads it.
The layout is pure (sources/genericdevice/genericdevice.cpp) and tested
by tst_genericdevice. ElementPictureFactory gains pictureFromDefinition()
to draw the preview with the same code as a placed element.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -51,6 +51,7 @@
|
||||
#include "ElementsCollection/xmlelementcollection.h"
|
||||
#include "NameList/nameslist.h"
|
||||
#include "elementdialog.h"
|
||||
#include "genericdevice/genericdevicewizard.h"
|
||||
#include "qetapp.h"
|
||||
#include "qetgraphicsitem/element.h"
|
||||
#include "qetinformation.h"
|
||||
@@ -2416,6 +2417,64 @@ void DiagramView::generateCabinetThumbnails()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief DiagramView::addGenericDevice
|
||||
Edit > Add > Generic device. Open the wizard; on Finish, write the box
|
||||
it describes as an ordinary symbol into the folder "Generic devices" of
|
||||
this project's embedded collection and put it on the cursor, ready to
|
||||
be placed. The file name carries a short uuid, so two devices given the
|
||||
same name never overwrite each other.
|
||||
*/
|
||||
void DiagramView::addGenericDevice()
|
||||
{
|
||||
QETProject *project = m_diagram ? m_diagram->project() : nullptr;
|
||||
if (!project || project->isReadOnly() || m_diagram->isReadOnly()) {
|
||||
return;
|
||||
}
|
||||
XmlElementCollection *collection = project->embeddedElementCollection();
|
||||
if (!collection) {
|
||||
return;
|
||||
}
|
||||
|
||||
//Measured with the fonts the folio draws with, so names fit
|
||||
const GenericDevice::Fonts fonts{QETApp::diagramTextsFont(7),
|
||||
QETApp::dynamicTextsItemFont(9)};
|
||||
GenericDeviceWizard wizard(fonts, this);
|
||||
if (wizard.exec() != QDialog::Accepted) {
|
||||
return;
|
||||
}
|
||||
const GenericDevice::Spec spec = wizard.spec();
|
||||
|
||||
const QString dir_name = QStringLiteral("Generic devices");
|
||||
const QString dir_path = QStringLiteral("import/") + dir_name;
|
||||
if (!collection->exist(dir_path))
|
||||
{
|
||||
NamesList dir_names;
|
||||
dir_names.addName(QStringLiteral("en"), dir_name);
|
||||
//Stored per language, like an element's names: not tr(), which
|
||||
//would store the interface's language under "en"
|
||||
dir_names.addName(QStringLiteral("fr"), QStringLiteral("Appareils génériques"));
|
||||
if (!collection->createDir(QStringLiteral("import"), dir_name, dir_names)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const QString file_name = QET::stringToFileName(spec.name)
|
||||
+ QLatin1Char('-')
|
||||
+ QUuid::createUuid().toString(QUuid::Id128).left(8)
|
||||
+ QStringLiteral(".elmt");
|
||||
QDomDocument doc;
|
||||
const QDomElement definition = GenericDevice::toDefinition(
|
||||
spec, fonts, doc, QetVersion::currentVersion().toString());
|
||||
if (!collection->addElementDefinition(dir_path, file_name, definition)) {
|
||||
return;
|
||||
}
|
||||
project->setModified(true);
|
||||
|
||||
const ElementsLocation location(dir_path + QLatin1Char('/') + file_name, project);
|
||||
startElementPlacement(location, defaultPlacementPos());
|
||||
}
|
||||
|
||||
/**
|
||||
@return l'editeur de schemas parent ou 0
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user