Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

various fixes in dxf export, import

improve error handing when loading file (FS#658)
update script bindings
  • Loading branch information...
commit 68bd23291e250fe3f2d59be1f348e11bfd84cfc1 1 parent d5db02c
@qcad authored
View
2  scripts/File/NewFile/NewFile.js
@@ -102,6 +102,8 @@ NewFile.createMdiChild = function(fileName, nameFilter) {
text += qsTr("No suitable Importer found. "
+ "Please check file format and extension.");
break;
+ case RDocumentInterface.IoErrorPermission:
+ case RDocumentInterface.IoErrorNotFound:
case RDocumentInterface.IoErrorGeneralImportError:
text += qsTr("Please check your access rights, "
+ "the file format and file extension.");
View
2  src/3rdparty/dxflib/src/dl_dxf.cpp
@@ -1152,7 +1152,7 @@ void DL_Dxf::addMText(DL_CreationInterface* creationInterface) {
// height
getRealValue(40, 2.5),
// width
- getRealValue(41, 100.0),
+ getRealValue(41, 0.0),
// attachment point
getIntValue(71, 1),
// drawing direction
View
43 src/3rdparty/dxflib/src/dl_entities.h
@@ -722,31 +722,24 @@ struct DXFLIB_EXPORT DL_TextData {
* Constructor.
* Parameters: see member variables.
*/
- DL_TextData(double tipx, double tipy, double tipz,
- double tapx, double tapy, double tapz,
- double tHeight, double tXScaleFactor,
- int tTextGenerationFlags,
- int tHJustification,
- int tVJustification,
- const std::string& tText,
- const std::string& tStyle,
- double tAngle) {
- ipx = tipx;
- ipy = tipy;
- ipz = tipz;
-
- apx = tapx;
- apy = tapy;
- apz = tapz;
-
- height = tHeight;
- xScaleFactor = tXScaleFactor;
- textGenerationFlags = tTextGenerationFlags;
- hJustification = tHJustification;
- vJustification = tVJustification;
- text = tText;
- style = tStyle;
- angle = tAngle;
+ DL_TextData(double ipx, double ipy, double ipz,
+ double apx, double apy, double apz,
+ double height, double xScaleFactor,
+ int textGenerationFlags,
+ int hJustification,
+ int vJustification,
+ const std::string& text,
+ const std::string& style,
+ double angle)
+ : ipx(ipx), ipy(ipy), ipz(ipz),
+ apx(apx), apy(apy), apz(apz),
+ height(height), xScaleFactor(xScaleFactor),
+ textGenerationFlags(textGenerationFlags),
+ hJustification(hJustification),
+ vJustification(vJustification),
+ text(text),
+ style(style),
+ angle(angle) {
}
/*! X Coordinate of insertion point. */
View
11 src/core/RDocumentInterface.cpp
@@ -911,10 +911,19 @@ RDocumentInterface::IoErrorCode RDocumentInterface::importFile(
clearCaches();
- if (QFileInfo(fileName).size()==0) {
+ QFileInfo fi(fileName);
+ if (fi.size()==0) {
return RDocumentInterface::IoErrorZeroSize;
}
+ if (!fi.exists()) {
+ return RDocumentInterface::IoErrorNotFound;
+ }
+
+ if (!fi.isReadable()) {
+ return RDocumentInterface::IoErrorPermission;
+ }
+
RFileImporter* fileImporter = RFileImporterRegistry::getFileImporter(
fileName, nameFilter, document, mainWindow, mainWindow);
if (fileImporter == NULL) {
View
18 src/core/RDocumentInterface.h
@@ -91,17 +91,25 @@ class QCADCORE_EXPORT RDocumentInterface {
*/
IoErrorNoImporterFound,
/**
+ * File size is zero bytes.
+ */
+ IoErrorZeroSize,
+ /**
+ * File not found.
+ */
+ IoErrorNotFound,
+ /**
+ * No permissions to read file.
+ */
+ IoErrorPermission,
+ /**
* General import error, i.e. non of the errors above.
*/
IoErrorGeneralImportError,
/**
* General import error if an URL was given, i.e. non of the errors above.
*/
- IoErrorGeneralImportUrlError,
- /**
- * File size is zero bytes.
- */
- IoErrorZeroSize
+ IoErrorGeneralImportUrlError
};
public:
View
2  src/entity/RTextEntity.cpp
@@ -155,6 +155,8 @@ void RTextEntity::print(QDebug dbg) const {
dbg.nospace() << ", alignmentPoint: " << getAlignmentPoint()
<< ", position: " << getPosition()
<< ", text: " << getPlainText()
+ << ", textHeight: " << getTextHeight()
+ << ", textWidth: " << getTextWidth()
<< ", drawingDirection: " << getDrawingDirection()
<< ")";
}
View
46 src/io/dxf/RDxfExporter.cpp
@@ -133,29 +133,34 @@ bool RDxfExporter::exportFile(const QString& fileName, const QString& nameFilter
// STYLE:
qDebug() << "writing styles...";
+ QList<DL_StyleData> uniqueTextStyles;
// write one text style for each new, unique combination of font, size, etc:
- QList<REntity::Id> styleIds = document->queryAllEntities(false, true).toList();
- for (int i=0; i<styleIds.size(); i++) {
- REntity::Id id = styleIds[i];
+ QList<REntity::Id> entityIds = document->queryAllEntities(false, true).toList();
+ for (int i=0; i<entityIds.size(); i++) {
+ REntity::Id id = entityIds[i];
QSharedPointer<REntity> entity = document->queryEntityDirect(id);
QSharedPointer<RTextEntity> textEntity = entity.dynamicCast<RTextEntity>();
if (textEntity.isNull()) {
continue;
}
+ // getStyle assignes a new, unique name for the style:
DL_StyleData style = getStyle(*textEntity);
style.bold = textEntity->isBold();
style.italic = textEntity->isItalic();
- if (textStyles.contains(style)) {
+ if (uniqueTextStyles.contains(style)) {
+ textStyleCounter--;
continue;
}
- textStyles.append(style);
+ textStyles.insert(id, style.name.c_str());
+
+ uniqueTextStyles.append(style);
}
- dw->tableStyle(textStyles.size());
- for (int i=0; i<textStyles.size(); i++) {
- DL_StyleData style = textStyles[i];
+ dw->tableStyle(uniqueTextStyles.size());
+ for (int i=0; i<uniqueTextStyles.size(); i++) {
+ DL_StyleData style = uniqueTextStyles[i];
dxf.writeStyle(*dw, style);
}
dw->tableEnd();
@@ -870,6 +875,13 @@ void RDxfExporter::writeText(const RTextEntity& t) {
}
void RDxfExporter::writeSimpleText(const RTextEntity& t) {
+ REntity::Id id = t.getId();
+ if (!textStyles.contains(id)) {
+ qWarning() << "RDxfExporter::writeSimpleText: "
+ << "no style for entity with ID: " << id;
+ return;
+ }
+ QString styleName = textStyles.value(t.getId());
DL_TextData data(
t.getPosition().x,
t.getPosition().y,
@@ -877,13 +889,13 @@ void RDxfExporter::writeSimpleText(const RTextEntity& t) {
t.getAlignmentPoint().x,
t.getAlignmentPoint().y,
0.0,
- t.getHeight(),
+ t.getTextHeight(),
1.0, // x scale factor
0, // text gen flags
0, // h just
0, // v just
(const char*)t.getEscapedText().toLatin1(),
- (const char*)t.getFontName().toLatin1(),
+ (const char*)styleName.toLatin1(),
t.getAngle());
if (t.getHAlign()==RS::HAlignAlign && t.getVAlign()==RS::VAlignBottom) {
@@ -924,6 +936,14 @@ void RDxfExporter::writeSimpleText(const RTextEntity& t) {
}
void RDxfExporter::writeMText(const RTextEntity& t) {
+ REntity::Id id = t.getId();
+ if (!textStyles.contains(id)) {
+ qWarning() << "RDxfExporter::writeMText: "
+ << "no style for entity with ID: " << id;
+ return;
+ }
+ QString styleName = textStyles.value(t.getId());
+
int attachmentPoint=1;
switch (t.getHAlign()) {
default:
@@ -988,14 +1008,14 @@ void RDxfExporter::writeMText(const RTextEntity& t) {
0.0,
0.0,
0.0,
- t.getHeight(),
- t.getWidth(),
+ t.getTextHeight(),
+ t.getTextWidth(),
attachmentPoint,
drawingDirection,
lineSpacingStyle,
t.getLineSpacingFactor(),
(const char*)t.getEscapedText().toLatin1(),
- (const char*)t.getFontName().toLatin1(),
+ (const char*)styleName.toLatin1(),
t.getAngle()),
attributes);
}
View
3  src/io/dxf/RDxfExporter.h
@@ -120,7 +120,8 @@ class QCADDXF_EXPORT RDxfExporter: public RFileExporter {
DL_WriterA* dw;
DL_Attributes attributes;
int textStyleCounter;
- QList<DL_StyleData> textStyles;
+ QMap<int, QString> textStyles;
+ //QList<DL_StyleData> textStyles;
// maps image entity IDs to handles:
QMap<int, int> imageHandles;
};
View
5 src/io/dxf/RDxfImporter.cpp
@@ -657,7 +657,7 @@ void RDxfImporter::addText(const DL_TextData& data) {
RS::VAlign valign;
RS::HAlign halign;
//RVector refPoint;
- double angle = data.angle;
+ //double angle = data.angle;
RDxfTextStyle s = textStyles.value(data.style.c_str(), RDxfTextStyle());
@@ -733,7 +733,8 @@ void RDxfImporter::addText(const DL_TextData& data) {
}
//int drawingDirection = 5;
- double width = 100.0;
+ //double width = 100.0;
+ double width = 0.0;
RTextData textData(
RVector::invalid, RVector::invalid,
View
20 src/scripting/ecmaapi/generated/REcmaDocumentInterface.cpp
@@ -332,6 +332,21 @@
QScriptValue::ReadOnly);
+ ctor.setProperty("IoErrorZeroSize",
+ QScriptValue(RDocumentInterface::IoErrorZeroSize),
+ QScriptValue::ReadOnly);
+
+
+ ctor.setProperty("IoErrorNotFound",
+ QScriptValue(RDocumentInterface::IoErrorNotFound),
+ QScriptValue::ReadOnly);
+
+
+ ctor.setProperty("IoErrorPermission",
+ QScriptValue(RDocumentInterface::IoErrorPermission),
+ QScriptValue::ReadOnly);
+
+
ctor.setProperty("IoErrorGeneralImportError",
QScriptValue(RDocumentInterface::IoErrorGeneralImportError),
QScriptValue::ReadOnly);
@@ -342,11 +357,6 @@
QScriptValue::ReadOnly);
- ctor.setProperty("IoErrorZeroSize",
- QScriptValue(RDocumentInterface::IoErrorZeroSize),
- QScriptValue::ReadOnly);
-
-
// enum conversions:
qScriptRegisterMetaType<RDocumentInterface::IoErrorCode>(
View
17 support/ecmagenerator/src/srcml/RDocumentInterface.srcml
@@ -147,6 +147,19 @@ dir="./core" filename="RDocumentInterface.h">
<expr>
<name>IoErrorNoImporterFound</name>
</expr>,
+ <comment type="block">/** * File size is zero bytes. */</comment>
+ <expr>
+ <name>IoErrorZeroSize</name>
+ </expr>,
+ <comment type="block">/** * File not found. */</comment>
+ <expr>
+ <name>IoErrorNotFound</name>
+ </expr>,
+ <comment type="block">/** * No permissions to read file.
+ */</comment>
+ <expr>
+ <name>IoErrorPermission</name>
+ </expr>,
<comment type="block">/** * General import error, i.e. non of the
errors above. */</comment>
<expr>
@@ -156,10 +169,6 @@ dir="./core" filename="RDocumentInterface.h">
given, i.e. non of the errors above. */</comment>
<expr>
<name>IoErrorGeneralImportUrlError</name>
- </expr>,
- <comment type="block">/** * File size is zero bytes. */</comment>
- <expr>
- <name>IoErrorZeroSize</name>
</expr>}</block>;</enum></public>
<public>public:
<constructor_decl>
View
74 support/ecmagenerator/src/srcml/RDxfExporter.srcml
@@ -67,6 +67,8 @@ dir="./io/dxf" filename="RDxfExporter.h">
<class_decl>class
<name>RProgressHandler</name>;</class_decl>
<class_decl>class
+ <name>RSolidEntity</name>;</class_decl>
+ <class_decl>class
<name>RSplineEntity</name>;</class_decl>
<class_decl>class
<name>RTextEntity</name>;</class_decl>
@@ -398,6 +400,34 @@ dir="./io/dxf" filename="RDxfExporter.h">
<type>
<name>void</name>
</type>
+ <name>writeSimpleText</name>
+ <parameter_list>(
+ <param>
+ <decl>
+ <type>
+ <name>const</name>
+ <name>RTextEntity</name>&amp;</type>
+ <name>t</name>
+ </decl>
+ </param>)</parameter_list>;</function_decl>
+ <function_decl>
+ <type>
+ <name>void</name>
+ </type>
+ <name>writeMText</name>
+ <parameter_list>(
+ <param>
+ <decl>
+ <type>
+ <name>const</name>
+ <name>RTextEntity</name>&amp;</type>
+ <name>t</name>
+ </decl>
+ </param>)</parameter_list>;</function_decl>
+ <function_decl>
+ <type>
+ <name>void</name>
+ </type>
<name>writeDimension</name>
<parameter_list>(
<param>
@@ -440,6 +470,34 @@ dir="./io/dxf" filename="RDxfExporter.h">
<type>
<name>void</name>
</type>
+ <name>writeImage</name>
+ <parameter_list>(
+ <param>
+ <decl>
+ <type>
+ <name>const</name>
+ <name>RImageEntity</name>&amp;</type>
+ <name>img</name>
+ </decl>
+ </param>)</parameter_list>;</function_decl>
+ <function_decl>
+ <type>
+ <name>void</name>
+ </type>
+ <name>writeSolid</name>
+ <parameter_list>(
+ <param>
+ <decl>
+ <type>
+ <name>const</name>
+ <name>RSolidEntity</name>&amp;</type>
+ <name>sol</name>
+ </decl>
+ </param>)</parameter_list>;</function_decl>
+ <function_decl>
+ <type>
+ <name>void</name>
+ </type>
<name>writeBlockReference</name>
<parameter_list>(
<param>
@@ -619,6 +677,22 @@ dir="./io/dxf" filename="RDxfExporter.h">
</argument>&gt;</argument_list></name>
</type>
<name>textStyles</name>
+ </decl>;</decl_stmt>
+ <comment type="line">// maps image entity IDs to
+ handles:</comment>
+ <decl_stmt>
+ <decl>
+ <type>
+ <name>QMap
+ <argument_list>&lt;
+ <argument>
+ <name>int</name>
+ </argument>,
+ <argument>
+ <name>int</name>
+ </argument>&gt;</argument_list></name>
+ </type>
+ <name>imageHandles</name>
</decl>;</decl_stmt></private>}</block>;</class>
<macro>
<name>Q_DECLARE_METATYPE</name>
View
9 support/ecmagenerator/src/srcml/RObject.srcml
@@ -604,14 +604,7 @@ dir="./core" filename="RObject.h">
<comment type="block">/** * \nonscriptable */</comment>
<function_decl>
<type>
- <name>QMap
- <argument_list>&lt;
- <argument>
- <name>QString</name>
- </argument>,
- <argument>
- <name>QVariant</name>
- </argument>&gt;</argument_list></name>
+ <name>QVariantMap</name>
</type>
<name>getCustomProperties</name>
<parameter_list>()</parameter_list>
View
15 support/ecmagenerator/src/srcml/RS.srcml
@@ -383,16 +383,13 @@ dir="./core" filename="RS.h">
<name>TextDrawingDirection</name>
<block>{
<expr>
- <name>LeftToRight</name>
- </expr>,
+ <name>LeftToRight</name>= 1</expr>,
<comment type="block">/**&lt; Left to right */</comment>
<expr>
- <name>TopToBottom</name>
- </expr>,
+ <name>TopToBottom</name>= 3</expr>,
<comment type="block">/**&lt; Top to bottom */</comment>
<expr>
- <name>ByStyle</name>
- </expr>
+ <name>ByStyle</name>= 5</expr>
<comment type="block">/**&lt; Inherited from associated text
style */</comment>}</block>;</enum>
<comment type="block">/** * Line spacing style for texts.
@@ -401,13 +398,11 @@ dir="./core" filename="RS.h">
<name>TextLineSpacingStyle</name>
<block>{
<expr>
- <name>AtLeast</name>
- </expr>,
+ <name>AtLeast</name>= 1</expr>,
<comment type="block">/**&lt; Taller characters will override
*/</comment>
<expr>
- <name>Exact</name>
- </expr>
+ <name>Exact</name>= 2</expr>
<comment type="block">/**&lt; Taller characters will not override
*/</comment>}</block>;</enum>
<comment type="block">/** * End used to specify from which end of
View
9 support/ecmagenerator/src/srcml/RSettings.srcml
@@ -771,14 +771,7 @@ dir="./core" filename="RSettings.h">
<decl>
<type>
<name>static</name>
- <name>QMap
- <argument_list>&lt;
- <argument>
- <name>QString</name>
- </argument>,
- <argument>
- <name>QVariant</name>
- </argument>&gt;</argument_list></name>
+ <name>QVariantMap</name>
</type>
<name>cache</name>
</decl>;</decl_stmt>
View
4 support/ecmagenerator/src/srcml/RVersion.srcml
@@ -24,7 +24,7 @@ dir="./core" filename="RVersion.h">
Application Framework. */</comment>
<cpp:define>#
<cpp:directive>define</cpp:directive>
- <name>R_QCAD_VERSION_STRING</name>"3.1.0 Beta 1"</cpp:define>
+ <name>R_QCAD_VERSION_STRING</name>"3.1.0 Beta 2"</cpp:define>
<cpp:define>#
<cpp:directive>define</cpp:directive>
<name>R_QCAD_VERSION_MAJOR</name>3</cpp:define>
@@ -36,7 +36,7 @@ dir="./core" filename="RVersion.h">
<name>R_QCAD_VERSION_REV</name>0</cpp:define>
<cpp:define>#
<cpp:directive>define</cpp:directive>
- <name>R_QCAD_VERSION_BUILD</name>1</cpp:define>
+ <name>R_QCAD_VERSION_BUILD</name>2</cpp:define>
<cpp:endif>#
<cpp:directive>endif</cpp:directive></cpp:endif>
</unit>
View
4 support/ecmagenerator/src/xml/RDocumentInterface.xml
@@ -18,9 +18,11 @@ xmlns:rs="http://www.ribbonsoft.com">
<enum name="IoErrorCode">
<value name="IoErrorNoError" />
<value name="IoErrorNoImporterFound" />
+ <value name="IoErrorZeroSize" />
+ <value name="IoErrorNotFound" />
+ <value name="IoErrorPermission" />
<value name="IoErrorGeneralImportError" />
<value name="IoErrorGeneralImportUrlError" />
- <value name="IoErrorZeroSize" />
</enum>
<constructor>
<variant>
View
1  support/ecmagenerator/src/xml/RDxfExporter.xml
@@ -13,6 +13,7 @@ xmlns:rs="http://www.ribbonsoft.com">
<class_decl name="RPointEntity" />
<class_decl name="RPolylineEntity" />
<class_decl name="RProgressHandler" />
+ <class_decl name="RSolidEntity" />
<class_decl name="RSplineEntity" />
<class_decl name="RTextEntity" />
<class name="RDxfExporter"
Please sign in to comment.
Something went wrong with that request. Please try again.