diff --git a/sources/ElementsCollection/elementcollectionhandler.cpp b/sources/ElementsCollection/elementcollectionhandler.cpp index 8d88b7cc0..653516593 100644 --- a/sources/ElementsCollection/elementcollectionhandler.cpp +++ b/sources/ElementsCollection/elementcollectionhandler.cpp @@ -26,8 +26,8 @@ /******************************************************/ ECHStrategy::ECHStrategy(ElementsLocation &source, ElementsLocation &destination) : - m_source(source), - m_destination (destination) + m_source(source), + m_destination (destination) {} ECHStrategy::~ECHStrategy() {} @@ -35,12 +35,12 @@ ECHStrategy::~ECHStrategy() {} /******************************************************/ ECHSFileToFile::ECHSFileToFile(ElementsLocation &source, ElementsLocation &destination) : - ECHStrategy(source, destination) + ECHStrategy(source, destination) {} ElementsLocation ECHSFileToFile::copy() { - //Check if the destination already have an item with the same name of the item to copy + //Check if the destination already have an item with the same name of the item to copy ElementsLocation location(m_destination.fileSystemPath() + "/" + m_source.fileName()); QString rename; if (location.exist()) @@ -69,32 +69,32 @@ ElementsLocation ECHSFileToFile::copy() else return ElementsLocation(); } - + if (m_source.isElement()) return copyElement(m_source, m_destination, rename); - else + else return copyDirectory(m_source, m_destination, rename); } ElementsLocation ECHSFileToFile::copyDirectory(ElementsLocation &source, ElementsLocation &destination, const QString& rename) { - QDir source_dir(source.fileSystemPath()); - QDir destination_dir(destination.fileSystemPath()); - + QDir source_dir(source.fileSystemPath()); + QDir destination_dir(destination.fileSystemPath()); + if (!source_dir.exists() || !destination_dir.exists()) return ElementsLocation(); - - QString new_dir_name = rename.isEmpty() ? source_dir.dirName() : rename; - - //Create a new dir - if (destination_dir.mkdir(new_dir_name)) - { - //The new created directory - QDir created_dir(destination_dir.canonicalPath() + "/" + new_dir_name); - - //Copy the qet_directory file - QFile::copy(source_dir.canonicalPath() + "/qet_directory", created_dir.canonicalPath() + "/qet_directory"); - - //Copy all dirs found in source_dir to destination_dir + + QString new_dir_name = rename.isEmpty() ? source_dir.dirName() : rename; + + //Create a new dir + if (destination_dir.mkdir(new_dir_name)) + { + //The new created directory + QDir created_dir(destination_dir.canonicalPath() + "/" + new_dir_name); + + //Copy the qet_directory file + QFile::copy(source_dir.canonicalPath() + "/qet_directory", created_dir.canonicalPath() + "/qet_directory"); + + //Copy all dirs found in source_dir to destination_dir ElementsLocation created_location(created_dir.canonicalPath()); //Used this bool when user drop a folder into itself to avoid infinite recursive creation of the dropped dir bool copy_itself = false; @@ -116,30 +116,30 @@ ElementsLocation ECHSFileToFile::copyDirectory(ElementsLocation &source, Element copyDirectory(sub_source, created_location); } - //Copy all elements found in source_dir to destination_dir - source_dir.setNameFilters(QStringList() << "*.elmt"); - foreach(QString str, source_dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name)) - { + //Copy all elements found in source_dir to destination_dir + source_dir.setNameFilters(QStringList() << "*.elmt"); + foreach(QString str, source_dir.entryList(QDir::Files | QDir::NoDotAndDotDot, QDir::Name)) + { ElementsLocation sub_source(source.fileSystemPath() + "/" + str); - copyElement(sub_source, created_location); - } - - return created_location; - } - + copyElement(sub_source, created_location); + } + + return created_location; + } + return ElementsLocation(); } ElementsLocation ECHSFileToFile::copyElement(ElementsLocation &source, ElementsLocation &destination, const QString& rename) { - QString new_elmt_name = rename.isEmpty() ? source.fileName() : rename; - bool rb = QFile::copy(source.fileSystemPath(), destination.fileSystemPath() + "/" + new_elmt_name); - if (rb) + QString new_elmt_name = rename.isEmpty() ? source.fileName() : rename; + bool rb = QFile::copy(source.fileSystemPath(), destination.fileSystemPath() + "/" + new_elmt_name); + if (rb) { #ifdef Q_OS_WIN - //On windows when user drag and drop an element from the common elements collection - //to the custom elements collection, the element file stay in read only mode, and so - //user can't save the element + //On windows when user drag and drop an element from the common elements collection + //to the custom elements collection, the element file stay in read only mode, and so + //user can't save the element extern Q_CORE_EXPORT int qt_ntfs_permission_lookup; qt_ntfs_permission_lookup++; QFile file(destination.fileSystemPath() + "/" + new_elmt_name); @@ -153,7 +153,7 @@ ElementsLocation ECHSFileToFile::copyElement(ElementsLocation &source, ElementsL #endif return ElementsLocation (destination.fileSystemPath() + "/" + new_elmt_name); } - else + else return ElementsLocation(); } @@ -165,7 +165,7 @@ ECHSXmlToFile::ECHSXmlToFile(ElementsLocation &source, ElementsLocation &destina ElementsLocation ECHSXmlToFile::copy() { - //Check if the destination already have an item with the same name of the item to copy + //Check if the destination already have an item with the same name of the item to copy ElementsLocation location(m_destination.fileSystemPath() + "/" + m_source.fileName()); QString rename; if (location.exist()) @@ -194,7 +194,7 @@ ElementsLocation ECHSXmlToFile::copy() else return ElementsLocation(); } - + if (m_source.isElement()) return copyElement(m_source, m_destination, rename); else @@ -204,61 +204,61 @@ ElementsLocation ECHSXmlToFile::copy() ElementsLocation ECHSXmlToFile::copyDirectory(ElementsLocation &source, ElementsLocation &destination, const QString& rename) { QDir destination_dir(destination.fileSystemPath()); - + if (!(destination_dir.exists() && source.exist())) return ElementsLocation(); - + QString new_dir_name = rename.isEmpty() ? source.fileName() : rename; - - //Create new dir + + //Create new dir if (destination_dir.mkdir(new_dir_name)) { QDir created_dir(destination_dir.canonicalPath() + "/" + new_dir_name); ElementsLocation created_location(created_dir.canonicalPath()); - - //Create the qet-directory file + + //Create the qet-directory file QDomDocument document; QDomElement root = document.createElement("qet-directory"); document.appendChild(root); root.appendChild(source.nameList().toXml(document)); - + QString filepath = created_dir.canonicalPath() + "/qet_directory"; QET::writeXmlFile(document, filepath); - - //Create all directory found in source to created_dir + + //Create all directory found in source to created_dir XmlElementCollection *project_collection = source.projectCollection(); - + QStringList directories_names = project_collection->directoriesNames( project_collection->directory(source.collectionPath(false)) ); foreach(QString name, directories_names) { ElementsLocation sub_source_dir(source.projectCollectionPath() + "/" + name); copyDirectory(sub_source_dir, created_location); } - - //Create all elements found in source to destination + + //Create all elements found in source to destination QStringList elements_names = project_collection->elementsNames( project_collection->directory(source.collectionPath(false))) ; foreach (QString name, elements_names) { ElementsLocation source_element(source.projectCollectionPath() + "/" + name); copyElement(source_element, created_location); } - + return created_location; } - + return ElementsLocation(); } ElementsLocation ECHSXmlToFile::copyElement(ElementsLocation &source, ElementsLocation &destination, const QString& rename) { if (!(destination.exist() && source.exist())) return ElementsLocation(); - + QString new_element_name = rename.isEmpty() ? source.fileName() : rename; - - //Get the xml descrption of the element + + //Get the xml descrption of the element QDomDocument document; document.appendChild(document.importNode(source.xml(), true)); - - //Create the .elmt file + + //Create the .elmt file QString filepath = destination.fileSystemPath() + "/" + new_element_name; if (QET::writeXmlFile(document, filepath)) return ElementsLocation(filepath); @@ -275,10 +275,10 @@ ECHSToXml::ECHSToXml(ElementsLocation &source, ElementsLocation &destination) : ElementsLocation ECHSToXml::copy() { if (!(m_source.exist() && m_destination.isDirectory() && m_destination.isProject())) return ElementsLocation(); - - //Check if the destination already have an item with the same name of the item to copy + + //Check if the destination already have an item with the same name of the item to copy ElementsLocation location(m_destination.projectCollectionPath() + "/" + m_source.fileName()); - + QString rename; if (location.exist()) { @@ -291,7 +291,7 @@ ElementsLocation ECHSToXml::copy() else return ElementsLocation(); } - + return m_destination.projectCollection()->copy(m_source, m_destination, rename); } @@ -305,7 +305,7 @@ ElementCollectionHandler::ElementCollectionHandler() {} ElementCollectionHandler::~ElementCollectionHandler() { - if (m_strategy) delete m_strategy; + if (m_strategy) delete m_strategy; } /** @@ -320,11 +320,11 @@ ElementCollectionHandler::~ElementCollectionHandler() ElementsLocation ElementCollectionHandler::copy(ElementsLocation &source, ElementsLocation &destination) { if (!source.exist() || !destination.exist() || destination.isElement()) return ElementsLocation(); - - if (source.isFileSystem() && destination.isFileSystem()) m_strategy = new ECHSFileToFile(source, destination); + + if (source.isFileSystem() && destination.isFileSystem()) m_strategy = new ECHSFileToFile(source, destination); if (source.isProject() && destination.isFileSystem()) m_strategy = new ECHSXmlToFile(source, destination); else if (destination.isProject()) m_strategy = new ECHSToXml(source, destination); - + if (m_strategy) return m_strategy->copy(); else @@ -342,31 +342,31 @@ ElementsLocation ElementCollectionHandler::copy(ElementsLocation &source, Elemen */ ElementsLocation ElementCollectionHandler::createDir(ElementsLocation &parent, const QString &name, const NamesList &name_list) { - //Parent must be a directorie and writable + //Parent must be a directorie and writable if (!(parent.isDirectory() && parent.isWritable() && parent.exist())) { qDebug() << "ElementCollectionHandler::createDir : the prerequisites are not valid. " << parent; return ElementsLocation(); } - - //Directorie to create must not already exist + + //Directorie to create must not already exist ElementsLocation created_dir = parent; created_dir.addToPath(name); if (created_dir.exist()) { return ElementsLocation(); } - - //Location is a file system + + //Location is a file system if (parent.isFileSystem()) { - + QDir parent_dir(parent.fileSystemPath()); - + if (parent_dir.mkdir(name)) { - //Create the qet-directory file + //Create the qet-directory file QDomDocument document; QDomElement root = document.createElement("qet-directory"); document.appendChild(root); root.appendChild(name_list.toXml(document)); - + QString filepath = created_dir.fileSystemPath() + "/qet_directory"; if (!QET::writeXmlFile(document, filepath)) { qDebug() << "ElementCollectionHandler::createDir : write qet-directory file failed"; @@ -388,7 +388,7 @@ ElementsLocation ElementCollectionHandler::createDir(ElementsLocation &parent, c return ElementsLocation(); } } - + return ElementsLocation(); } @@ -403,35 +403,35 @@ ElementsLocation ElementCollectionHandler::createDir(ElementsLocation &parent, c bool ElementCollectionHandler::importFromProject(QETProject *project, ElementsLocation &location) { if (!(location.isElement() && location.exist() && location.isProject())) return false; - + ElementsLocation destination(location.collectionPath(false), project); if (destination.exist()) return true; - + QList names; - - //Get the parent of location and find if exist in embedded collection of project + + //Get the parent of location and find if exist in embedded collection of project ElementsLocation source = location.parent(); names.append(location.fileName()); - + destination = ElementsLocation(source.collectionPath(), project); - - //Go back until to find an existing directory in destination + + //Go back until to find an existing directory in destination while (!destination.exist()) { names.append(source.fileName()); source = source.parent(); destination = ElementsLocation(source.collectionPath(), project); } - + XmlElementCollection *collection = project->embeddedElementCollection(); - + while (!names.isEmpty()) { source.addToPath(names.takeLast()); destination = collection->copy(source, destination, QString(), false); - + if (!destination.exist()) return false; } - + return true; } @@ -447,23 +447,23 @@ bool ElementCollectionHandler::setNames(ElementsLocation &location, const NamesL if ( !(location.exist() && location.isWritable()) ) { return false; } - + if (location.isFileSystem()) { if (location.isDirectory()) { QDomDocument document; QDomElement root = document.createElement("qet-directory"); document.appendChild(root); root.appendChild(name_list.toXml(document)); - + QString filepath = location.fileSystemPath() + "/qet_directory"; if (!QET::writeXmlFile(document, filepath)) { qDebug() << "ElementCollectionHandler::setNames : write qet-directory file failed"; return false; } - + return true; } - + if (location.isElement()) { QDomDocument document; document.appendChild(document.importNode(location.xml(), true)); @@ -471,19 +471,19 @@ bool ElementCollectionHandler::setNames(ElementsLocation &location, const NamesL qDebug() << "ElementCollectionHandler::setNames : failed to load xml document from file"; return false; } - + QDomElement document_element = document.documentElement(); document_element.replaceChild(name_list.toXml(document), document_element.firstChildElement("names")); return true; } } - + if (location.isProject()) { QDomElement element = location.xml(); QDomDocument document = element.ownerDocument(); element.replaceChild(name_list.toXml(document), element.firstChildElement("names")); return true; } - + return false; } diff --git a/sources/conductornumexport.cpp b/sources/conductornumexport.cpp index 581bdc145..1eab20d6d 100644 --- a/sources/conductornumexport.cpp +++ b/sources/conductornumexport.cpp @@ -31,10 +31,10 @@ * @param parent : parent widget */ ConductorNumExport::ConductorNumExport(QETProject *project, QWidget *parent) : - m_project(project), - m_parent_widget(parent) + m_project(project), + m_parent_widget(parent) { - fillHash(); + fillHash(); } /** @@ -44,44 +44,44 @@ ConductorNumExport::ConductorNumExport(QETProject *project, QWidget *parent) : */ bool ConductorNumExport::toCsv() { - QString name = QObject::tr("numero_de_fileries_") + m_project->title() + ".csv"; -// if(!name.endsWith(".csv")) { -// name += ".csv"; -// } - - QString filename = QFileDialog::getSaveFileName(m_parent_widget, QObject::tr("Enregister sous... "), name, QObject::tr("Fichiers csv (*.csv)")); - QFile file(filename); - if(!filename.isEmpty()) - { - if(QFile::exists(filename)) - { - // if file already exist -> delete it - if(!QFile::remove(filename)) - { - QMessageBox::critical(m_parent_widget, QObject::tr("Erreur"), - QObject::tr("Impossible de remplacer le fichier!\n\n")+ - "Destination : "+filename+"\n"); - return false; - } - } - if (file.open(QIODevice::WriteOnly | QIODevice::Text)) - { - QTextStream stream(&file); + QString name = QObject::tr("numero_de_fileries_") + m_project->title() + ".csv"; + // if(!name.endsWith(".csv")) { + // name += ".csv"; + // } + + QString filename = QFileDialog::getSaveFileName(m_parent_widget, QObject::tr("Enregister sous... "), name, QObject::tr("Fichiers csv (*.csv)")); + QFile file(filename); + if(!filename.isEmpty()) + { + if(QFile::exists(filename)) + { + // if file already exist -> delete it + if(!QFile::remove(filename)) + { + QMessageBox::critical(m_parent_widget, QObject::tr("Erreur"), + QObject::tr("Impossible de remplacer le fichier!\n\n")+ + "Destination : "+filename+"\n"); + return false; + } + } + if (file.open(QIODevice::WriteOnly | QIODevice::Text)) + { + QTextStream stream(&file); #if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) // ### Qt 6: remove - stream << wiresNum() << endl; + stream << wiresNum() << endl; #else - stream << wiresNum() << &Qt::endl(stream); + stream << wiresNum() << &Qt::endl(stream); #endif - } - else { - return false; - } - } - else { - return false; - } - - return true; + } + else { + return false; + } + } + else { + return false; + } + + return true; } /** @@ -90,18 +90,18 @@ bool ConductorNumExport::toCsv() */ QString ConductorNumExport::wiresNum() const { - QString csv; - - QStringList list = m_hash.keys(); - list.sort(); - for (QString key : list) - { - for (int i=0; idiagrams()) - { - DiagramContent dc(d, false); - for (Conductor *c : dc.conductors()) - { - QString num = c->textItem()->toPlainText(); - if (num.isEmpty() || num.contains(rx)) { - continue; - } - - //We must to define if the connected terminal is a folio report, if it is the case - //we don't add the num to the hash because the terminal doesn't represent a real terminal. - if(!(c->terminal1->parentElement()->linkType() & Element::AllReport)) - { - int value = m_hash.value(num, 0); - ++value; - m_hash.insert(num, value); - } - if(!(c->terminal2->parentElement()->linkType() & Element::AllReport)) - { - int value = m_hash.value(num, 0); - ++value; - m_hash.insert(num, value); - } - } - } + //We used this rx to avoid insert num composed only withe white space. + QRegularExpression rx("^ *$"); + for (Diagram *d : m_project->diagrams()) + { + DiagramContent dc(d, false); + for (Conductor *c : dc.conductors()) + { + QString num = c->textItem()->toPlainText(); + if (num.isEmpty() || num.contains(rx)) { + continue; + } + + //We must to define if the connected terminal is a folio report, if it is the case + //we don't add the num to the hash because the terminal doesn't represent a real terminal. + if(!(c->terminal1->parentElement()->linkType() & Element::AllReport)) + { + int value = m_hash.value(num, 0); + ++value; + m_hash.insert(num, value); + } + if(!(c->terminal2->parentElement()->linkType() & Element::AllReport)) + { + int value = m_hash.value(num, 0); + ++value; + m_hash.insert(num, value); + } + } + } } diff --git a/sources/conductornumexport.h b/sources/conductornumexport.h index 440b778c7..c741f8de9 100644 --- a/sources/conductornumexport.h +++ b/sources/conductornumexport.h @@ -29,18 +29,18 @@ class QWidget; */ class ConductorNumExport { - public: - ConductorNumExport(QETProject *project, QWidget *parent = nullptr); - bool toCsv(); - QString wiresNum() const; - - private: - void fillHash(); - - private: - QETProject *m_project = nullptr; - QHash m_hash; - QWidget *m_parent_widget = nullptr; + public: + ConductorNumExport(QETProject *project, QWidget *parent = nullptr); + bool toCsv(); + QString wiresNum() const; + + private: + void fillHash(); + + private: + QETProject *m_project = nullptr; + QHash m_hash; + QWidget *m_parent_widget = nullptr; }; #endif // ConductorNumExport_H diff --git a/sources/createdxf.cpp b/sources/createdxf.cpp index 78645d518..5e04ed579 100644 --- a/sources/createdxf.cpp +++ b/sources/createdxf.cpp @@ -42,339 +42,339 @@ Createdxf::~Createdxf() void Createdxf::dxfBegin (const QString& fileName) { - // Creation of an output stream object in text mode. - // Header section of every dxf file. - if (!fileName.isEmpty()) { - QFile file(fileName); - if (!file.open(QFile::WriteOnly)) { - // error message - QMessageBox errorFileOpen; - errorFileOpen.setIcon(QMessageBox::Warning); - errorFileOpen.setText("Error: "+fileName+" Could Not be Opened."); - errorFileOpen.setInformativeText("Close all Files and Try Again."); - errorFileOpen.exec(); - exit(0); - } else { - QTextStream To_Dxf(&file); - To_Dxf << 999 << "\r\n"; - To_Dxf << "QET" << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "SECTION" << "\r\n"; - To_Dxf << 2 << "\r\n"; - To_Dxf << "HEADER" << "\r\n"; - To_Dxf << 9 << "\r\n"; - To_Dxf << "$ACADVER" << "\r\n"; - To_Dxf << 1 << "\r\n"; - To_Dxf << "AC1006" << "\r\n"; - To_Dxf << 9 << "\r\n"; - To_Dxf << "$INSBASE" << "\r\n"; - To_Dxf << 10 << "\r\n"; - To_Dxf << "0.0" << "\r\n"; - To_Dxf << 20 << "\r\n"; - To_Dxf << "0.0" << "\r\n"; - To_Dxf << 30 << "\r\n"; - To_Dxf << "0.0" << "\r\n"; - To_Dxf << 9 << "\r\n"; - - To_Dxf << "$EXTMIN" << "\r\n"; - To_Dxf << 10 << "\r\n"; - To_Dxf << "0.0" << "\r\n"; - To_Dxf << 20 << "\r\n"; - To_Dxf << "0.0" << "\r\n"; - To_Dxf << 9 << "\r\n"; - To_Dxf << "$EXTMAX" << "\r\n"; - To_Dxf << 10 << "\r\n"; - To_Dxf << "4000.0" << "\r\n"; - To_Dxf << 20 << "\r\n"; - To_Dxf << "4000.0" << "\r\n"; - - To_Dxf << 9 << "\r\n"; - To_Dxf << "$LIMMIN" << "\r\n"; - To_Dxf << 10 << "\r\n"; - To_Dxf << "0.0" << "\r\n"; - To_Dxf << 20 << "\r\n"; - To_Dxf << "0.0" << "\r\n"; - To_Dxf << 9 << "\r\n"; - To_Dxf << "$LIMMAX" << "\r\n"; - To_Dxf << 10 << "\r\n"; - To_Dxf << "4000.0" << "\r\n"; - To_Dxf << 20 << "\r\n"; - To_Dxf << "4000.0" << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "ENDSEC" << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "SECTION" << "\r\n"; - To_Dxf << 2 << "\r\n"; - To_Dxf << "TABLES" << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "TABLE" << "\r\n"; - To_Dxf << 2 << "\r\n"; - - To_Dxf << "VPORT" << "\r\n"; - To_Dxf << 70 << "\r\n"; - To_Dxf << 1 << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "VPORT" << "\r\n"; - To_Dxf << 2 << "\r\n"; - To_Dxf << "*ACTIVE" << "\r\n"; - To_Dxf << 70 << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << 10 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 20 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 11 << "\r\n"; - To_Dxf << 1.0 << "\r\n"; - To_Dxf << 21 << "\r\n"; - To_Dxf << 1.0 << "\r\n"; - To_Dxf << 12 << "\r\n"; - To_Dxf << 2000 << "\r\n"; - To_Dxf << 22 << "\r\n"; - To_Dxf << 1350 << "\r\n"; - To_Dxf << 13 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 23 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 14 << "\r\n"; - To_Dxf << 1.0 << "\r\n"; - To_Dxf << 24 << "\r\n"; - To_Dxf << 1.0 << "\r\n"; - To_Dxf << 15 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 25 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 16 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 26 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 36 << "\r\n"; - To_Dxf << 1.0 << "\r\n"; - To_Dxf << 17 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 27 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 37 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 40 << "\r\n"; - To_Dxf << 2732.5 << "\r\n"; - To_Dxf << 41 << "\r\n"; - To_Dxf << 2.558 << "\r\n"; - To_Dxf << 42 << "\r\n"; - To_Dxf << 50.0 << "\r\n"; - To_Dxf << 43 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 44 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 50 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 51 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; - To_Dxf << 71 << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << 72 << "\r\n"; - To_Dxf << 100 << "\r\n"; - To_Dxf << 73 << "\r\n"; - To_Dxf << 1 << "\r\n"; - To_Dxf << 74 << "\r\n"; - To_Dxf << 1 << "\r\n"; - To_Dxf << 75 << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << 76 << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << 77 << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << 78 << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "ENDTAB" << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "TABLE" << "\r\n"; - To_Dxf << 2 << "\r\n"; - - To_Dxf << "LTYPE" << "\r\n"; - To_Dxf << 70 << "\r\n"; - To_Dxf << 1 << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "LTYPE" << "\r\n"; - To_Dxf << 2 << "\r\n"; - To_Dxf << "CONTINUOUS" << "\r\n"; - To_Dxf << 70 << "\r\n"; - To_Dxf << 64 << "\r\n"; - To_Dxf << 3 << "\r\n"; - To_Dxf << "Solid Line" << "\r\n"; - To_Dxf << 72 << "\r\n"; - To_Dxf << 65 << "\r\n"; - To_Dxf << 73 << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << 40 << "\r\n"; - To_Dxf << 0.00 << "\r\n"; - To_Dxf << 0 << "\r\n"; - - To_Dxf << "ENDTAB" << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "ENDSEC" << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "SECTION" << "\r\n"; - To_Dxf << 2 << "\r\n"; - To_Dxf << "BLOCKS" << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "ENDSEC" << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "SECTION" << "\r\n"; - To_Dxf << 2 << "\r\n"; - To_Dxf << "ENTITIES" << "\r\n"; - file.close(); - } - } + // Creation of an output stream object in text mode. + // Header section of every dxf file. + if (!fileName.isEmpty()) { + QFile file(fileName); + if (!file.open(QFile::WriteOnly)) { + // error message + QMessageBox errorFileOpen; + errorFileOpen.setIcon(QMessageBox::Warning); + errorFileOpen.setText("Error: "+fileName+" Could Not be Opened."); + errorFileOpen.setInformativeText("Close all Files and Try Again."); + errorFileOpen.exec(); + exit(0); + } else { + QTextStream To_Dxf(&file); + To_Dxf << 999 << "\r\n"; + To_Dxf << "QET" << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "SECTION" << "\r\n"; + To_Dxf << 2 << "\r\n"; + To_Dxf << "HEADER" << "\r\n"; + To_Dxf << 9 << "\r\n"; + To_Dxf << "$ACADVER" << "\r\n"; + To_Dxf << 1 << "\r\n"; + To_Dxf << "AC1006" << "\r\n"; + To_Dxf << 9 << "\r\n"; + To_Dxf << "$INSBASE" << "\r\n"; + To_Dxf << 10 << "\r\n"; + To_Dxf << "0.0" << "\r\n"; + To_Dxf << 20 << "\r\n"; + To_Dxf << "0.0" << "\r\n"; + To_Dxf << 30 << "\r\n"; + To_Dxf << "0.0" << "\r\n"; + To_Dxf << 9 << "\r\n"; + + To_Dxf << "$EXTMIN" << "\r\n"; + To_Dxf << 10 << "\r\n"; + To_Dxf << "0.0" << "\r\n"; + To_Dxf << 20 << "\r\n"; + To_Dxf << "0.0" << "\r\n"; + To_Dxf << 9 << "\r\n"; + To_Dxf << "$EXTMAX" << "\r\n"; + To_Dxf << 10 << "\r\n"; + To_Dxf << "4000.0" << "\r\n"; + To_Dxf << 20 << "\r\n"; + To_Dxf << "4000.0" << "\r\n"; + + To_Dxf << 9 << "\r\n"; + To_Dxf << "$LIMMIN" << "\r\n"; + To_Dxf << 10 << "\r\n"; + To_Dxf << "0.0" << "\r\n"; + To_Dxf << 20 << "\r\n"; + To_Dxf << "0.0" << "\r\n"; + To_Dxf << 9 << "\r\n"; + To_Dxf << "$LIMMAX" << "\r\n"; + To_Dxf << 10 << "\r\n"; + To_Dxf << "4000.0" << "\r\n"; + To_Dxf << 20 << "\r\n"; + To_Dxf << "4000.0" << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "ENDSEC" << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "SECTION" << "\r\n"; + To_Dxf << 2 << "\r\n"; + To_Dxf << "TABLES" << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "TABLE" << "\r\n"; + To_Dxf << 2 << "\r\n"; + + To_Dxf << "VPORT" << "\r\n"; + To_Dxf << 70 << "\r\n"; + To_Dxf << 1 << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "VPORT" << "\r\n"; + To_Dxf << 2 << "\r\n"; + To_Dxf << "*ACTIVE" << "\r\n"; + To_Dxf << 70 << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << 10 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 20 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 11 << "\r\n"; + To_Dxf << 1.0 << "\r\n"; + To_Dxf << 21 << "\r\n"; + To_Dxf << 1.0 << "\r\n"; + To_Dxf << 12 << "\r\n"; + To_Dxf << 2000 << "\r\n"; + To_Dxf << 22 << "\r\n"; + To_Dxf << 1350 << "\r\n"; + To_Dxf << 13 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 23 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 14 << "\r\n"; + To_Dxf << 1.0 << "\r\n"; + To_Dxf << 24 << "\r\n"; + To_Dxf << 1.0 << "\r\n"; + To_Dxf << 15 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 25 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 16 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 26 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 36 << "\r\n"; + To_Dxf << 1.0 << "\r\n"; + To_Dxf << 17 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 27 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 37 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 40 << "\r\n"; + To_Dxf << 2732.5 << "\r\n"; + To_Dxf << 41 << "\r\n"; + To_Dxf << 2.558 << "\r\n"; + To_Dxf << 42 << "\r\n"; + To_Dxf << 50.0 << "\r\n"; + To_Dxf << 43 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 44 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 50 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 51 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; + To_Dxf << 71 << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << 72 << "\r\n"; + To_Dxf << 100 << "\r\n"; + To_Dxf << 73 << "\r\n"; + To_Dxf << 1 << "\r\n"; + To_Dxf << 74 << "\r\n"; + To_Dxf << 1 << "\r\n"; + To_Dxf << 75 << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << 76 << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << 77 << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << 78 << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "ENDTAB" << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "TABLE" << "\r\n"; + To_Dxf << 2 << "\r\n"; + + To_Dxf << "LTYPE" << "\r\n"; + To_Dxf << 70 << "\r\n"; + To_Dxf << 1 << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "LTYPE" << "\r\n"; + To_Dxf << 2 << "\r\n"; + To_Dxf << "CONTINUOUS" << "\r\n"; + To_Dxf << 70 << "\r\n"; + To_Dxf << 64 << "\r\n"; + To_Dxf << 3 << "\r\n"; + To_Dxf << "Solid Line" << "\r\n"; + To_Dxf << 72 << "\r\n"; + To_Dxf << 65 << "\r\n"; + To_Dxf << 73 << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << 40 << "\r\n"; + To_Dxf << 0.00 << "\r\n"; + To_Dxf << 0 << "\r\n"; + + To_Dxf << "ENDTAB" << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "ENDSEC" << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "SECTION" << "\r\n"; + To_Dxf << 2 << "\r\n"; + To_Dxf << "BLOCKS" << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "ENDSEC" << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "SECTION" << "\r\n"; + To_Dxf << 2 << "\r\n"; + To_Dxf << "ENTITIES" << "\r\n"; + file.close(); + } + } } /* End Section of every DXF File*/ void Createdxf::dxfEnd (const QString& fileName) { - // Creation of an output stream object in text mode. - if (!fileName.isEmpty()) { - QFile file(fileName); - if (!file.open(QFile::Append)) { - // error message - QMessageBox errorFileOpen; - errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); - errorFileOpen.setInformativeText("Close all Files and Re-Run"); - errorFileOpen.exec(); - } else { - QTextStream To_Dxf(&file); - To_Dxf << 0 << "\r\n"; - To_Dxf << "ENDSEC" << "\r\n"; - To_Dxf << 0 << "\r\n"; - To_Dxf << "EOF"; - file.close(); - } - } + // Creation of an output stream object in text mode. + if (!fileName.isEmpty()) { + QFile file(fileName); + if (!file.open(QFile::Append)) { + // error message + QMessageBox errorFileOpen; + errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); + errorFileOpen.setInformativeText("Close all Files and Re-Run"); + errorFileOpen.exec(); + } else { + QTextStream To_Dxf(&file); + To_Dxf << 0 << "\r\n"; + To_Dxf << "ENDSEC" << "\r\n"; + To_Dxf << 0 << "\r\n"; + To_Dxf << "EOF"; + file.close(); + } + } } /* draw circle in dxf format*/ void Createdxf::drawCircle (const QString& fileName, double radius, double x, double y, int colour) { - if (!fileName.isEmpty()) { - QFile file(fileName); - if (!file.open(QFile::Append)) { - // error message - QMessageBox errorFileOpen; - errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); - errorFileOpen.setInformativeText("Close all Files and Re-Run"); - errorFileOpen.exec(); - } else { - QTextStream To_Dxf(&file); - // Draw the circle - To_Dxf << 0 << "\r\n"; - To_Dxf << "CIRCLE" << "\r\n"; - To_Dxf << 8 << "\r\n"; - To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) - To_Dxf << 62 << "\r\n"; - To_Dxf << colour << "\r\n"; // Colour Code - To_Dxf << 10 << "\r\n"; // XYZ is the Center point of circle - To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 20 << "\r\n"; - To_Dxf << y << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 30 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 40 << "\r\n"; - To_Dxf << radius << "\r\n"; // radius of circle - file.close(); - } - } + if (!fileName.isEmpty()) { + QFile file(fileName); + if (!file.open(QFile::Append)) { + // error message + QMessageBox errorFileOpen; + errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); + errorFileOpen.setInformativeText("Close all Files and Re-Run"); + errorFileOpen.exec(); + } else { + QTextStream To_Dxf(&file); + // Draw the circle + To_Dxf << 0 << "\r\n"; + To_Dxf << "CIRCLE" << "\r\n"; + To_Dxf << 8 << "\r\n"; + To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) + To_Dxf << 62 << "\r\n"; + To_Dxf << colour << "\r\n"; // Colour Code + To_Dxf << 10 << "\r\n"; // XYZ is the Center point of circle + To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 20 << "\r\n"; + To_Dxf << y << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 30 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 40 << "\r\n"; + To_Dxf << radius << "\r\n"; // radius of circle + file.close(); + } + } } /* draw line in DXF Format*/ void Createdxf::drawLine (const QString &fileName, double x1, double y1, double x2, double y2,const int &colour) { - if (!fileName.isEmpty()) { - QFile file(fileName); - if (!file.open(QFile::Append)) { - // error message - QMessageBox errorFileOpen; - errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); - errorFileOpen.setInformativeText("Close all Files and Re-Run"); - errorFileOpen.exec(); - } else { - QTextStream To_Dxf(&file); - // Draw the Line - To_Dxf << 0 << "\r\n"; - To_Dxf << "LINE" << "\r\n"; - To_Dxf << 8 << "\r\n"; - To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) - To_Dxf << 62 << "\r\n"; - To_Dxf << colour << "\r\n"; // Colour Code - To_Dxf << 10 << "\r\n"; - To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 20 << "\r\n"; - To_Dxf << y1 << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 30 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 11 << "\r\n"; - To_Dxf << x2 << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 21 << "\r\n"; - To_Dxf << y2 << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 31 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - file.close(); - } - } + if (!fileName.isEmpty()) { + QFile file(fileName); + if (!file.open(QFile::Append)) { + // error message + QMessageBox errorFileOpen; + errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); + errorFileOpen.setInformativeText("Close all Files and Re-Run"); + errorFileOpen.exec(); + } else { + QTextStream To_Dxf(&file); + // Draw the Line + To_Dxf << 0 << "\r\n"; + To_Dxf << "LINE" << "\r\n"; + To_Dxf << 8 << "\r\n"; + To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) + To_Dxf << 62 << "\r\n"; + To_Dxf << colour << "\r\n"; // Colour Code + To_Dxf << 10 << "\r\n"; + To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 20 << "\r\n"; + To_Dxf << y1 << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 30 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 11 << "\r\n"; + To_Dxf << x2 << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 21 << "\r\n"; + To_Dxf << y2 << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 31 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + file.close(); + } + } } long Createdxf::RGBcodeTable[255]{ - 0x000000, 0xff0000, 0xffff00, 0x00ff00, 0x00ffff, - 0x0000ff, 0xff00ff, 0xffffff, 0x414141, 0x808080, - 0xff0000, 0xffaaaa, 0xbd0000, 0xbd7e7e, 0x810000, - 0x815656, 0x680000, 0x684545, 0x4f0000, 0x4f3535, - 0xff3f00, 0xffbfaa, 0xbd2e00, 0xbd8d7e, 0x811f00, - 0x816056, 0x681900, 0x684e45, 0x4f1300, 0x4f3b35, - 0xff7f00, 0xffd4aa, 0xbd5e00, 0xbd9d7e, 0x814000, - 0x816b56, 0x683400, 0x685645, 0x4f2700, 0x4f4235, - 0xffbf00, 0xffeaaa, 0xbd8d00, 0xbdad7e, 0x816000, - 0x817656, 0x684e00, 0x685f45, 0x4f3b00, 0x4f4935, - 0xffff00, 0xffffaa, 0xbdbd00, 0xbdbd7e, 0x818100, - 0x818156, 0x686800, 0x686845, 0x4f4f00, 0x4f4f35, - 0xbfff00, 0xeaffaa, 0x8dbd00, 0xadbd7e, 0x608100, - 0x768156, 0x4e6800, 0x5f6845, 0x3b4f00, 0x494f35, - 0x7fff00, 0xd4ffaa, 0x5ebd00, 0x9dbd7e, 0x408100, - 0x6b8156, 0x346800, 0x566845, 0x274f00, 0x424f35, - 0x3fff00, 0xbfffaa, 0x2ebd00, 0x8dbd7e, 0x1f8100, - 0x608156, 0x196800, 0x4e6845, 0x134f00, 0x3b4f35, - 0x00ff00, 0xaaffaa, 0x00bd00, 0x7ebd7e, 0x008100, - 0x568156, 0x006800, 0x456845, 0x004f00, 0x354f35, - 0x00ff3f, 0xaaffbf, 0x00bd2e, 0x7ebd8d, 0x00811f, - 0x568160, 0x006819, 0x45684e, 0x004f13, 0x354f3b, - 0x00ff7f, 0xaaffd4, 0x00bd5e, 0x7ebd9d, 0x008140, - 0x56816b, 0x006834, 0x456856, 0x004f27, 0x354f42, - 0x00ffbf, 0xaaffea, 0x00bd8d, 0x7ebdad, 0x008160, - 0x568176, 0x00684e, 0x45685f, 0x004f3b, 0x354f49, - 0x00ffff, 0xaaffff, 0x00bdbd, 0x7ebdbd, 0x008181, - 0x568181, 0x006868, 0x456868, 0x004f4f, 0x354f4f, - 0x00bfff, 0xaaeaff, 0x008dbd, 0x7eadbd, 0x006081, - 0x567681, 0x004e68, 0x455f68, 0x003b4f, 0x35494f, - 0x007fff, 0xaad4ff, 0x005ebd, 0x7e9dbd, 0x004081, - 0x566b81, 0x003468, 0x455668, 0x00274f, 0x35424f, - 0x003fff, 0xaabfff, 0x002ebd, 0x7e8dbd, 0x001f81, - 0x566081, 0x001968, 0x454e68, 0x00134f, 0x353b4f, - 0x0000ff, 0xaaaaff, 0x0000bd, 0x7e7ebd, 0x000081, - 0x565681, 0x000068, 0x454568, 0x00004f, 0x35354f, - 0x3f00ff, 0xbfaaff, 0x2e00bd, 0x8d7ebd, 0x1f0081, - 0x605681, 0x190068, 0x4e4568, 0x13004f, 0x3b354f, - 0x7f00ff, 0xd4aaff, 0x5e00bd, 0x9d7ebd, 0x400081, - 0x6b5681, 0x340068, 0x564568, 0x27004f, 0x42354f, - 0xbf00ff, 0xeeaaff, 0x8d00bd, 0xad7ebd, 0x600081, - 0x765681, 0x4e0068, 0x5f4568, 0x3b004f, 0x49354f, - 0xff00ff, 0xffaaff, 0xbd00bd, 0xbd7ebd, 0x810081, - 0x815681, 0x680068, 0x684568, 0x4f004f, 0x4f354f, - 0xff00bf, 0xffaaea, 0xbd008d, 0xbd7ead, 0x810060, - 0x815676, 0x68004e, 0x68455f, 0x4f003b, 0x4f3549, - 0xff007f, 0xffaad4, 0xbd005e, 0xbd7e9d, 0x810040, - 0x81566b, 0x680034, 0x684556, 0x4f0027, 0x4f3542, - 0xff003f, 0xffaabf, 0xbd002e, 0xbd7e8d, 0x81001f, - 0x815660, 0x680019, 0x68454e, 0x4f0013, 0x4f353b, - 0x333333, 0x505050, 0x696969, 0x828282, 0xbebebe + 0x000000, 0xff0000, 0xffff00, 0x00ff00, 0x00ffff, + 0x0000ff, 0xff00ff, 0xffffff, 0x414141, 0x808080, + 0xff0000, 0xffaaaa, 0xbd0000, 0xbd7e7e, 0x810000, + 0x815656, 0x680000, 0x684545, 0x4f0000, 0x4f3535, + 0xff3f00, 0xffbfaa, 0xbd2e00, 0xbd8d7e, 0x811f00, + 0x816056, 0x681900, 0x684e45, 0x4f1300, 0x4f3b35, + 0xff7f00, 0xffd4aa, 0xbd5e00, 0xbd9d7e, 0x814000, + 0x816b56, 0x683400, 0x685645, 0x4f2700, 0x4f4235, + 0xffbf00, 0xffeaaa, 0xbd8d00, 0xbdad7e, 0x816000, + 0x817656, 0x684e00, 0x685f45, 0x4f3b00, 0x4f4935, + 0xffff00, 0xffffaa, 0xbdbd00, 0xbdbd7e, 0x818100, + 0x818156, 0x686800, 0x686845, 0x4f4f00, 0x4f4f35, + 0xbfff00, 0xeaffaa, 0x8dbd00, 0xadbd7e, 0x608100, + 0x768156, 0x4e6800, 0x5f6845, 0x3b4f00, 0x494f35, + 0x7fff00, 0xd4ffaa, 0x5ebd00, 0x9dbd7e, 0x408100, + 0x6b8156, 0x346800, 0x566845, 0x274f00, 0x424f35, + 0x3fff00, 0xbfffaa, 0x2ebd00, 0x8dbd7e, 0x1f8100, + 0x608156, 0x196800, 0x4e6845, 0x134f00, 0x3b4f35, + 0x00ff00, 0xaaffaa, 0x00bd00, 0x7ebd7e, 0x008100, + 0x568156, 0x006800, 0x456845, 0x004f00, 0x354f35, + 0x00ff3f, 0xaaffbf, 0x00bd2e, 0x7ebd8d, 0x00811f, + 0x568160, 0x006819, 0x45684e, 0x004f13, 0x354f3b, + 0x00ff7f, 0xaaffd4, 0x00bd5e, 0x7ebd9d, 0x008140, + 0x56816b, 0x006834, 0x456856, 0x004f27, 0x354f42, + 0x00ffbf, 0xaaffea, 0x00bd8d, 0x7ebdad, 0x008160, + 0x568176, 0x00684e, 0x45685f, 0x004f3b, 0x354f49, + 0x00ffff, 0xaaffff, 0x00bdbd, 0x7ebdbd, 0x008181, + 0x568181, 0x006868, 0x456868, 0x004f4f, 0x354f4f, + 0x00bfff, 0xaaeaff, 0x008dbd, 0x7eadbd, 0x006081, + 0x567681, 0x004e68, 0x455f68, 0x003b4f, 0x35494f, + 0x007fff, 0xaad4ff, 0x005ebd, 0x7e9dbd, 0x004081, + 0x566b81, 0x003468, 0x455668, 0x00274f, 0x35424f, + 0x003fff, 0xaabfff, 0x002ebd, 0x7e8dbd, 0x001f81, + 0x566081, 0x001968, 0x454e68, 0x00134f, 0x353b4f, + 0x0000ff, 0xaaaaff, 0x0000bd, 0x7e7ebd, 0x000081, + 0x565681, 0x000068, 0x454568, 0x00004f, 0x35354f, + 0x3f00ff, 0xbfaaff, 0x2e00bd, 0x8d7ebd, 0x1f0081, + 0x605681, 0x190068, 0x4e4568, 0x13004f, 0x3b354f, + 0x7f00ff, 0xd4aaff, 0x5e00bd, 0x9d7ebd, 0x400081, + 0x6b5681, 0x340068, 0x564568, 0x27004f, 0x42354f, + 0xbf00ff, 0xeeaaff, 0x8d00bd, 0xad7ebd, 0x600081, + 0x765681, 0x4e0068, 0x5f4568, 0x3b004f, 0x49354f, + 0xff00ff, 0xffaaff, 0xbd00bd, 0xbd7ebd, 0x810081, + 0x815681, 0x680068, 0x684568, 0x4f004f, 0x4f354f, + 0xff00bf, 0xffaaea, 0xbd008d, 0xbd7ead, 0x810060, + 0x815676, 0x68004e, 0x68455f, 0x4f003b, 0x4f3549, + 0xff007f, 0xffaad4, 0xbd005e, 0xbd7e9d, 0x810040, + 0x81566b, 0x680034, 0x684556, 0x4f0027, 0x4f3542, + 0xff003f, 0xffaabf, 0xbd002e, 0xbd7e8d, 0x81001f, + 0x815660, 0x680019, 0x68454e, 0x4f0013, 0x4f353b, + 0x333333, 0x505050, 0x696969, 0x828282, 0xbebebe }; /** @@ -388,24 +388,24 @@ long Createdxf::RGBcodeTable[255]{ */ int Createdxf::getcolorCode (const long red, const long green, const long blue) { - long acirgb, r,g,b; - long mindst = 2147483647L; - long dst = 0; - int minndx = 0; - for ( int i = 0; i < 254; i++ ) - { - acirgb = RGBcodeTable[i]; - b = ( acirgb & 0xffL ); - g = ( acirgb & 0xff00L ) >> 8; - r = acirgb >> 16; - dst = abs ( r-red) + abs ( g -green) + abs (b-blue); - if ( dst < mindst ) - { - minndx = i; - mindst = dst; - } - } - return minndx; + long acirgb, r,g,b; + long mindst = 2147483647L; + long dst = 0; + int minndx = 0; + for ( int i = 0; i < 254; i++ ) + { + acirgb = RGBcodeTable[i]; + b = ( acirgb & 0xffL ); + g = ( acirgb & 0xff00L ) >> 8; + r = acirgb >> 16; + dst = abs ( r-red) + abs ( g -green) + abs (b-blue); + if ( dst < mindst ) + { + minndx = i; + mindst = dst; + } + } + return minndx; } /** @@ -417,16 +417,16 @@ int Createdxf::getcolorCode (const long red, const long green, const long blue) */ void Createdxf::drawLine(const QString &filepath, const QLineF &line, const int &colorcode) { drawLine(filepath, line.p1().x() * xScale, - sheetHeight - (line.p1().y() * yScale), - line.p2().x() * xScale, - sheetHeight - (line.p2().y() * yScale), - colorcode); + sheetHeight - (line.p1().y() * yScale), + line.p2().x() * xScale, + sheetHeight - (line.p2().y() * yScale), + colorcode); } void Createdxf::drawArcEllipse(const QString &file_path, qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal spanAngle, qreal hotspot_x, qreal hotspot_y, qreal rotation_angle, const int &colorcode) { // vector of parts of arc (stored as a pair of startAngle and spanAngle) for each quadrant. QVector< QPair > arc_parts_vector; - + if (spanAngle > 0) { qreal start = startAngle; qreal span; @@ -468,46 +468,46 @@ void Createdxf::drawArcEllipse(const QString &file_path, qreal x, qreal y, qreal arc_parts_vector.push_back(newPart); } } - + for (int i = 0; i < arc_parts_vector.size(); i++) { - + QPair arc = arc_parts_vector[i]; if (arc.second == 0) continue; qreal arc_startAngle = arc.first * 3.142/180; qreal arc_spanAngle = arc.second * 3.142/180; - + qreal a = w/2; qreal b = h/2; - + qreal x1 = x + w/2 + a*cos(arc_startAngle); qreal y1 = y - h/2 + b*sin(arc_startAngle); qreal x2 = x + w/2 + a*cos(arc_startAngle + arc_spanAngle); qreal y2 = y - h/2 + b*sin(arc_startAngle + arc_spanAngle); - - + + qreal mid_ellipse_x = x + w/2 + a*cos(arc_startAngle + arc_spanAngle/2); qreal mid_ellipse_y = y - h/2 + b*sin(arc_startAngle + arc_spanAngle/2); qreal mid_line_x = (x1+x2)/2; qreal mid_line_y = (y1+y2)/2; - + qreal x3 = (mid_ellipse_x + mid_line_x)/2; qreal y3 = (mid_ellipse_y + mid_line_y)/2; - + // find circumcenter of points (x1,y1), (x3,y3) and (x2,y2) qreal a1 = 2*x2 - 2*x1; qreal b1 = 2*y2 - 2*y1; qreal c1 = x1*x1 + y1*y1 - x2*x2 - y2*y2; - + qreal a2 = 2*x3 - 2*x1; qreal b2 = 2*y3 - 2*y1; qreal c2 = x1*x1 + y1*y1 - x3*x3 - y3*y3; - + qreal center_x = (b1*c2 - b2*c1) / (a1*b2 - a2*b1); qreal center_y = (a1*c2 - a2*c1) / (b1*a2 - b2*a1); - + qreal radius = sqrt( (x1-center_x)*(x1-center_x) + (y1-center_y)*(y1-center_y) ); - + if ( x1 > center_x && y1 > center_y ) arc_startAngle = asin( (y1 - center_y) / radius ); else if ( x1 > center_x && y1 < center_y ) @@ -516,9 +516,9 @@ void Createdxf::drawArcEllipse(const QString &file_path, qreal x, qreal y, qreal arc_startAngle = 3.142 + asin( (center_y - y1) / radius ); else arc_startAngle = 3.142 - asin( (y1 - center_y) / radius ); - + qreal arc_endAngle; - + if ( x2 > center_x && y2 > center_y ) arc_endAngle = asin( (y2 - center_y) / radius ); else if ( x2 > center_x && y2 < center_y ) @@ -527,13 +527,13 @@ void Createdxf::drawArcEllipse(const QString &file_path, qreal x, qreal y, qreal arc_endAngle = 3.142 + asin( (center_y - y2) / radius ); else arc_endAngle = 3.142 - asin( (y2 - center_y) / radius ); - + if (arc_endAngle < arc_startAngle) { qreal temp = arc_startAngle; arc_startAngle = arc_endAngle; arc_endAngle = temp; } - + QPointF transformed_point = ExportDialog::rotation_transformed(center_x, center_y, hotspot_x, hotspot_y, rotation_angle); center_x = transformed_point.x(); center_y = transformed_point.y(); @@ -541,7 +541,7 @@ void Createdxf::drawArcEllipse(const QString &file_path, qreal x, qreal y, qreal arc_startAngle *= 180/3.142; arc_endAngle -= rotation_angle; arc_startAngle -= rotation_angle; - + drawArc(file_path, center_x, center_y, radius, arc_startAngle, arc_endAngle, colorcode); } } @@ -555,101 +555,101 @@ void Createdxf::drawArcEllipse(const QString &file_path, qreal x, qreal y, qreal */ void Createdxf::drawEllipse(const QString &filepath, const QRectF &rect, const int &colorcode) { drawArcEllipse(filepath, rect.topLeft().x() * xScale, - sheetHeight - (rect.topLeft().y() * yScale), - rect.width() * xScale, - rect.height() * yScale, - 0, 360, 0, 0, 0, colorcode); + sheetHeight - (rect.topLeft().y() * yScale), + rect.width() * xScale, + rect.height() * yScale, + 0, 360, 0, 0, 0, colorcode); } /* draw rectangle in dxf format */ void Createdxf::drawRectangle (const QString &fileName, double x1, double y1, double width, double height, const int &colour) { - if (!fileName.isEmpty()) { - QFile file(fileName); - if (!file.open(QFile::Append)) { - // error message - QMessageBox errorFileOpen; - errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); - errorFileOpen.setInformativeText("Close all Files and Re-Run"); - errorFileOpen.exec(); - } else { - QTextStream To_Dxf(&file); - // Draw the Rectangle - To_Dxf << 0 << "\r\n"; - To_Dxf << "LINE" << "\r\n"; - To_Dxf << 8 << "\r\n"; - To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) - To_Dxf << 62 << "\r\n"; - To_Dxf << colour << "\r\n"; // Colour Code - To_Dxf << 10 << "\r\n"; - To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 20 << "\r\n"; - To_Dxf << y1 << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 30 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 11 << "\r\n"; - To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 21 << "\r\n"; - To_Dxf << y1 << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 31 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 0 << "\r\n"; - To_Dxf << "LINE" << "\r\n"; - To_Dxf << 8 << "\r\n"; - To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) - To_Dxf << 62 << "\r\n"; - To_Dxf << colour << "\r\n"; // Colour Code - To_Dxf << 10 << "\r\n"; - To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 20 << "\r\n"; - To_Dxf << y1 << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 30 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 11 << "\r\n"; - To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 21 << "\r\n"; - To_Dxf << y1+height << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 31 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 0 << "\r\n"; - To_Dxf << "LINE" << "\r\n"; - To_Dxf << 8 << "\r\n"; - To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) - To_Dxf << 62 << "\r\n"; - To_Dxf << colour << "\r\n"; // Colour Code - To_Dxf << 10 << "\r\n"; - To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 20 << "\r\n"; - To_Dxf << y1 << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 30 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 11 << "\r\n"; - To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 21 << "\r\n"; - To_Dxf << y1+height << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 31 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 0 << "\r\n"; - To_Dxf << "LINE" << "\r\n"; - To_Dxf << 8 << "\r\n"; - To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) - To_Dxf << 62 << "\r\n"; - To_Dxf << colour << "\r\n"; // Colour Code - To_Dxf << 10 << "\r\n"; - To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 20 << "\r\n"; - To_Dxf << y1+height << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 30 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 11 << "\r\n"; - To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 21 << "\r\n"; - To_Dxf << y1+height << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 31 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - file.close(); - } - } + if (!fileName.isEmpty()) { + QFile file(fileName); + if (!file.open(QFile::Append)) { + // error message + QMessageBox errorFileOpen; + errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); + errorFileOpen.setInformativeText("Close all Files and Re-Run"); + errorFileOpen.exec(); + } else { + QTextStream To_Dxf(&file); + // Draw the Rectangle + To_Dxf << 0 << "\r\n"; + To_Dxf << "LINE" << "\r\n"; + To_Dxf << 8 << "\r\n"; + To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) + To_Dxf << 62 << "\r\n"; + To_Dxf << colour << "\r\n"; // Colour Code + To_Dxf << 10 << "\r\n"; + To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 20 << "\r\n"; + To_Dxf << y1 << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 30 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 11 << "\r\n"; + To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 21 << "\r\n"; + To_Dxf << y1 << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 31 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 0 << "\r\n"; + To_Dxf << "LINE" << "\r\n"; + To_Dxf << 8 << "\r\n"; + To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) + To_Dxf << 62 << "\r\n"; + To_Dxf << colour << "\r\n"; // Colour Code + To_Dxf << 10 << "\r\n"; + To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 20 << "\r\n"; + To_Dxf << y1 << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 30 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 11 << "\r\n"; + To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 21 << "\r\n"; + To_Dxf << y1+height << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 31 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 0 << "\r\n"; + To_Dxf << "LINE" << "\r\n"; + To_Dxf << 8 << "\r\n"; + To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) + To_Dxf << 62 << "\r\n"; + To_Dxf << colour << "\r\n"; // Colour Code + To_Dxf << 10 << "\r\n"; + To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 20 << "\r\n"; + To_Dxf << y1 << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 30 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 11 << "\r\n"; + To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 21 << "\r\n"; + To_Dxf << y1+height << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 31 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 0 << "\r\n"; + To_Dxf << "LINE" << "\r\n"; + To_Dxf << 8 << "\r\n"; + To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) + To_Dxf << 62 << "\r\n"; + To_Dxf << colour << "\r\n"; // Colour Code + To_Dxf << 10 << "\r\n"; + To_Dxf << x1 << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 20 << "\r\n"; + To_Dxf << y1+height << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 30 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 11 << "\r\n"; + To_Dxf << x1+width << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 21 << "\r\n"; + To_Dxf << y1+height << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 31 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + file.close(); + } + } } /** @@ -661,123 +661,123 @@ void Createdxf::drawRectangle (const QString &fileName, double x1, double y1, do */ void Createdxf::drawRectangle(const QString &filepath, const QRectF &rect, const int &colorcode) { drawRectangle(filepath, rect.bottomLeft().x() * xScale, - sheetHeight - (rect.bottomLeft().y() * yScale), - rect.width() * xScale, - rect.height() * yScale, - colorcode); + sheetHeight - (rect.bottomLeft().y() * yScale), + rect.width() * xScale, + rect.height() * yScale, + colorcode); } /* draw arc in dx format */ void Createdxf::drawArc(const QString& fileName,double x,double y,double rad,double startAngle,double endAngle,int color) { - if (!fileName.isEmpty()) { - QFile file(fileName); - if (!file.open(QFile::Append)) { - // error message - QMessageBox errorFileOpen; - errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); - errorFileOpen.setInformativeText("Close all Files and Re-Run"); - errorFileOpen.exec(); - } else { - QTextStream To_Dxf(&file); - // Draw the arc - To_Dxf << 0 << "\r\n"; - To_Dxf << "ARC" << "\r\n"; - To_Dxf << 8 << "\r\n"; - To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) - To_Dxf << 62 << "\r\n"; - To_Dxf << color << "\r\n"; // Colour Code - To_Dxf << 10 << "\r\n"; // XYZ is the Center point of circle - To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 20 << "\r\n"; - To_Dxf << y << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 30 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 40 << "\r\n"; - To_Dxf << rad << "\r\n"; // radius of arc - To_Dxf << 50 << "\r\n"; - To_Dxf << startAngle<< "\r\n"; // start angle - To_Dxf << 51 << "\r\n"; - To_Dxf << endAngle << "\r\n"; // end angle - file.close(); - } - } + if (!fileName.isEmpty()) { + QFile file(fileName); + if (!file.open(QFile::Append)) { + // error message + QMessageBox errorFileOpen; + errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); + errorFileOpen.setInformativeText("Close all Files and Re-Run"); + errorFileOpen.exec(); + } else { + QTextStream To_Dxf(&file); + // Draw the arc + To_Dxf << 0 << "\r\n"; + To_Dxf << "ARC" << "\r\n"; + To_Dxf << 8 << "\r\n"; + To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) + To_Dxf << 62 << "\r\n"; + To_Dxf << color << "\r\n"; // Colour Code + To_Dxf << 10 << "\r\n"; // XYZ is the Center point of circle + To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 20 << "\r\n"; + To_Dxf << y << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 30 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 40 << "\r\n"; + To_Dxf << rad << "\r\n"; // radius of arc + To_Dxf << 50 << "\r\n"; + To_Dxf << startAngle<< "\r\n"; // start angle + To_Dxf << 51 << "\r\n"; + To_Dxf << endAngle << "\r\n"; // end angle + file.close(); + } + } } /* draw simple text in dxf format without any alignment specified */ void Createdxf::drawText(const QString& fileName, const QString& text,double x, double y, double height, double rotation, int colour) { - if (!fileName.isEmpty()) { - QFile file(fileName); - if (!file.open(QFile::Append)) { - // error message - QMessageBox errorFileOpen; - errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); - errorFileOpen.setInformativeText("Close all Files and Re-Run"); - errorFileOpen.exec(); - } else { - QTextStream To_Dxf(&file); - // Draw the circle - To_Dxf << 0 << "\r\n"; - To_Dxf << "TEXT" << "\r\n"; - To_Dxf << 8 << "\r\n"; - To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) - To_Dxf << 62 << "\r\n"; - To_Dxf << colour << "\r\n"; // Colour Code - To_Dxf << 10 << "\r\n"; // XYZ - To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 20 << "\r\n"; - To_Dxf << y << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 30 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 40 << "\r\n"; - To_Dxf << height << "\r\n"; // Text Height - To_Dxf << 1 << "\r\n"; - To_Dxf << text << "\r\n"; // Text Value - To_Dxf << 50 << "\r\n"; - To_Dxf << rotation << "\r\n"; // Text Rotation - file.close(); - } - } + if (!fileName.isEmpty()) { + QFile file(fileName); + if (!file.open(QFile::Append)) { + // error message + QMessageBox errorFileOpen; + errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); + errorFileOpen.setInformativeText("Close all Files and Re-Run"); + errorFileOpen.exec(); + } else { + QTextStream To_Dxf(&file); + // Draw the circle + To_Dxf << 0 << "\r\n"; + To_Dxf << "TEXT" << "\r\n"; + To_Dxf << 8 << "\r\n"; + To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) + To_Dxf << 62 << "\r\n"; + To_Dxf << colour << "\r\n"; // Colour Code + To_Dxf << 10 << "\r\n"; // XYZ + To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 20 << "\r\n"; + To_Dxf << y << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 30 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 40 << "\r\n"; + To_Dxf << height << "\r\n"; // Text Height + To_Dxf << 1 << "\r\n"; + To_Dxf << text << "\r\n"; // Text Value + To_Dxf << 50 << "\r\n"; + To_Dxf << rotation << "\r\n"; // Text Rotation + file.close(); + } + } } /* draw aligned text in DXF Format */ // leftAlign flag added. If the alignment requested is 'fit to width' and the text length is very small, // then the text is either centered or left-aligned, depnding on the value of leftAlign. void Createdxf::drawTextAligned(const QString& fileName, const QString& text,double x, double y, double height, double rotation, double oblique,int hAlign, int vAlign, double xAlign,int colour, - bool leftAlign, float scale) + bool leftAlign, float scale) { Q_UNUSED(scale); - - if (!fileName.isEmpty()) { - QFile file(fileName); - if (!file.open(QFile::Append)) { - // error message - QMessageBox errorFileOpen; - errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); - errorFileOpen.setInformativeText("Close all Files and Re-Run"); - errorFileOpen.exec(); - } else { - QTextStream To_Dxf(&file); - // Draw the circle - To_Dxf << 0 << "\r\n"; - To_Dxf << "TEXT" << "\r\n"; - To_Dxf << 8 << "\r\n"; - To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) - To_Dxf << 62 << "\r\n"; - To_Dxf << colour << "\r\n"; // Colour Code - To_Dxf << 10 << "\r\n"; // XYZ - To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 20 << "\r\n"; - To_Dxf << y << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 30 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - To_Dxf << 40 << "\r\n"; - To_Dxf << height << "\r\n"; // Text Height - To_Dxf << 1 << "\r\n"; - To_Dxf << text << "\r\n"; // Text Value - To_Dxf << 50 << "\r\n"; - To_Dxf << rotation << "\r\n"; // Text Rotation + + if (!fileName.isEmpty()) { + QFile file(fileName); + if (!file.open(QFile::Append)) { + // error message + QMessageBox errorFileOpen; + errorFileOpen.setText("Error: File "+fileName+" was not written correctly."); + errorFileOpen.setInformativeText("Close all Files and Re-Run"); + errorFileOpen.exec(); + } else { + QTextStream To_Dxf(&file); + // Draw the circle + To_Dxf << 0 << "\r\n"; + To_Dxf << "TEXT" << "\r\n"; + To_Dxf << 8 << "\r\n"; + To_Dxf << 0 << "\r\n"; // Layer number (default layer in autocad) + To_Dxf << 62 << "\r\n"; + To_Dxf << colour << "\r\n"; // Colour Code + To_Dxf << 10 << "\r\n"; // XYZ + To_Dxf << x << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 20 << "\r\n"; + To_Dxf << y << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 30 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + To_Dxf << 40 << "\r\n"; + To_Dxf << height << "\r\n"; // Text Height + To_Dxf << 1 << "\r\n"; + To_Dxf << text << "\r\n"; // Text Value + To_Dxf << 50 << "\r\n"; + To_Dxf << rotation << "\r\n"; // Text Rotation // If "Fit to width", then check if width of text < width specified then change it "center align or left align" if (hAlign == 5) { int xDiff = xAlign - x; @@ -789,23 +789,23 @@ void Createdxf::drawTextAligned(const QString& fileName, const QString& text,dou return; } } - - To_Dxf << 51 << "\r\n"; - To_Dxf << oblique << "\r\n"; // Text Obliqueness - To_Dxf << 72 << "\r\n"; - To_Dxf << hAlign << "\r\n"; // Text Horizontal Alignment - To_Dxf << 73 << "\r\n"; - To_Dxf << vAlign << "\r\n"; // Text Vertical Alignment - - if ((hAlign) || (vAlign)) { // Enter Second Point - To_Dxf << 11 << "\r\n"; // XYZ - To_Dxf << xAlign << "\r\n"; // X in UCS (User Coordinate System)coordinates - To_Dxf << 21 << "\r\n"; - To_Dxf << y << "\r\n"; // Y in UCS (User Coordinate System)coordinates - To_Dxf << 31 << "\r\n"; - To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates - } - file.close(); - } - } + + To_Dxf << 51 << "\r\n"; + To_Dxf << oblique << "\r\n"; // Text Obliqueness + To_Dxf << 72 << "\r\n"; + To_Dxf << hAlign << "\r\n"; // Text Horizontal Alignment + To_Dxf << 73 << "\r\n"; + To_Dxf << vAlign << "\r\n"; // Text Vertical Alignment + + if ((hAlign) || (vAlign)) { // Enter Second Point + To_Dxf << 11 << "\r\n"; // XYZ + To_Dxf << xAlign << "\r\n"; // X in UCS (User Coordinate System)coordinates + To_Dxf << 21 << "\r\n"; + To_Dxf << y << "\r\n"; // Y in UCS (User Coordinate System)coordinates + To_Dxf << 31 << "\r\n"; + To_Dxf << 0.0 << "\r\n"; // Z in UCS (User Coordinate System)coordinates + } + file.close(); + } + } } diff --git a/sources/diagramevent/diagrameventaddimage.cpp b/sources/diagramevent/diagrameventaddimage.cpp index 9941ab599..47cb67cfe 100644 --- a/sources/diagramevent/diagrameventaddimage.cpp +++ b/sources/diagramevent/diagrameventaddimage.cpp @@ -56,26 +56,26 @@ DiagramEventAddImage::~DiagramEventAddImage() */ void DiagramEventAddImage::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (m_image && event -> button() == Qt::LeftButton) - { - QPointF pos = event->scenePos(); - pos.rx() -= m_image->boundingRect().width()/2; - pos.ry() -= m_image->boundingRect().height()/2; - m_diagram -> undoStack().push (new AddItemCommand(m_image, m_diagram, pos)); - + if (m_image && event -> button() == Qt::LeftButton) + { + QPointF pos = event->scenePos(); + pos.rx() -= m_image->boundingRect().width()/2; + pos.ry() -= m_image->boundingRect().height()/2; + m_diagram -> undoStack().push (new AddItemCommand(m_image, m_diagram, pos)); + for (QGraphicsView *view : m_diagram->views()) { - view->setContextMenuPolicy((Qt::DefaultContextMenu)); + view->setContextMenuPolicy((Qt::DefaultContextMenu)); } - - m_running = false; - emit finish(); + + m_running = false; + emit finish(); event->setAccepted(true); - } - else if (m_image && event -> button() == Qt::RightButton) - { - m_image->setRotation(m_image->rotation() + 90); - event->setAccepted(true); - } + } + else if (m_image && event -> button() == Qt::RightButton) + { + m_image->setRotation(m_image->rotation() + 90); + event->setAccepted(true); + } } /** @@ -88,21 +88,21 @@ void DiagramEventAddImage::mouseMoveEvent(QGraphicsSceneMouseEvent *event) if (!m_image || event->buttons() != Qt::NoButton) { return; }; - - QPointF pos = event->scenePos(); - - if (!m_is_added) - { + + QPointF pos = event->scenePos(); + + if (!m_is_added) + { for (QGraphicsView *view : m_diagram->views()) { - view->setContextMenuPolicy((Qt::NoContextMenu)); + view->setContextMenuPolicy((Qt::NoContextMenu)); } - - m_diagram->addItem(m_image); - m_is_added = true; - } - - m_image->setPos(pos - m_image->boundingRect().center()); - event->setAccepted(true); + + m_diagram->addItem(m_image); + m_is_added = true; + } + + m_image->setPos(pos - m_image->boundingRect().center()); + event->setAccepted(true); } /** @@ -125,14 +125,14 @@ void DiagramEventAddImage::wheelEvent(QGraphicsSceneWheelEvent *event) if (!m_is_added || !m_image || event -> modifiers() != Qt::CTRL) { return; } - - qreal scaling = m_image->scale(); - event->delta() > 1? scaling += 0.01 : scaling -= 0.01; + + qreal scaling = m_image->scale(); + event->delta() > 1? scaling += 0.01 : scaling -= 0.01; if (scaling>0.01 && scaling <= 2) { - m_image->setScale(scaling); + m_image->setScale(scaling); } - - event->setAccepted(true); + + event->setAccepted(true); } /** @@ -141,8 +141,8 @@ void DiagramEventAddImage::wheelEvent(QGraphicsSceneWheelEvent *event) */ bool DiagramEventAddImage::isNull() const { - if (!m_image) return true; - return false; + if (!m_image) return true; + return false; } /** @@ -151,21 +151,21 @@ bool DiagramEventAddImage::isNull() const */ void DiagramEventAddImage::openDialog() { - if (m_diagram -> isReadOnly()) return; - - //Open dialog for select image - QString pathPictures = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); - QString fileName = QFileDialog::getOpenFileName(m_diagram->views().isEmpty()? nullptr : m_diagram->views().first(), QObject::tr("Selectionner une image..."), pathPictures, QObject::tr("Image Files (*.png *.jpg *.jpeg *.bmp *.svg)")); - - if (fileName.isEmpty()) return; - - QImage image(fileName); - if(image.isNull()) - { - QMessageBox::critical(m_diagram->views().isEmpty()? nullptr : m_diagram->views().first(), QObject::tr("Erreur"), QObject::tr("Impossible de charger l'image.")); - return; - } - - m_image = new DiagramImageItem (QPixmap::fromImage(image)); - m_running = true; + if (m_diagram -> isReadOnly()) return; + + //Open dialog for select image + QString pathPictures = QStandardPaths::writableLocation(QStandardPaths::PicturesLocation); + QString fileName = QFileDialog::getOpenFileName(m_diagram->views().isEmpty()? nullptr : m_diagram->views().first(), QObject::tr("Selectionner une image..."), pathPictures, QObject::tr("Image Files (*.png *.jpg *.jpeg *.bmp *.svg)")); + + if (fileName.isEmpty()) return; + + QImage image(fileName); + if(image.isNull()) + { + QMessageBox::critical(m_diagram->views().isEmpty()? nullptr : m_diagram->views().first(), QObject::tr("Erreur"), QObject::tr("Impossible de charger l'image.")); + return; + } + + m_image = new DiagramImageItem (QPixmap::fromImage(image)); + m_running = true; } diff --git a/sources/qetgraphicsitem/element.cpp b/sources/qetgraphicsitem/element.cpp index 173a4be83..5bc29dc0e 100644 --- a/sources/qetgraphicsitem/element.cpp +++ b/sources/qetgraphicsitem/element.cpp @@ -1525,7 +1525,7 @@ void Element::setUpFormula(bool code_letter) if(!m_freeze_label && !formula.isEmpty()) { DiagramContext dc = m_element_informations; - m_element_informations.addValue("label", actualLabel()); + m_element_informations.addValue("label", actualLabel()); emit elementInfoChange(dc, m_element_informations); } }