Permalink
Browse files

various fixes in dxf export, import

improve error handing when loading file (FS#658)
update script bindings
  • Loading branch information...
1 parent d5db02c commit 68bd23291e250fe3f2d59be1f348e11bfd84cfc1 @qcad committed May 22, 2013
@@ -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.");
@@ -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
@@ -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. */
@@ -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) {
@@ -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:
@@ -155,6 +155,8 @@ void RTextEntity::print(QDebug dbg) const {
dbg.nospace() << ", alignmentPoint: " << getAlignmentPoint()
<< ", position: " << getPosition()
<< ", text: " << getPlainText()
+ << ", textHeight: " << getTextHeight()
+ << ", textWidth: " << getTextWidth()
<< ", drawingDirection: " << getDrawingDirection()
<< ")";
}
@@ -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,20 +875,27 @@ 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,
0.0,
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);
}
@@ -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;
};
@@ -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,
@@ -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>(
@@ -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>
Oops, something went wrong.

0 comments on commit 68bd232

Please sign in to comment.