Skip to content

Commit

Permalink
dwg/dxf import: fix angle and alignment handing of (m)texts
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 19, 2019
1 parent 6090a93 commit 92e7faa
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 53 deletions.
9 changes: 5 additions & 4 deletions external/libdxfrw/drw_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ void DRW_Text::parseCode( int code, dxfReader *reader )
angle = reader->getDouble() / ARAD;
break;
case 51:
oblique = reader->getDouble();
oblique = reader->getDouble() / ARAD;
break;
case 71:
textgen = reader->getInt32();
Expand Down Expand Up @@ -1803,6 +1803,7 @@ bool DRW_MText::parseDwg( DRW::Version version, dwgBuffer *buf, duint32 bs )

extPoint = buf->get3BitDouble(); /* Extrusion 3BD 210 Undocumented; */
secPoint = buf->get3BitDouble(); /* X-axis dir 3BD 11 */
haveXAxis = true;
updateAngle();
widthscale = buf->getBitDouble(); /* Rect width BD 41 */
if ( version > DRW::AC1018 ) //2007+
Expand Down Expand Up @@ -2192,7 +2193,7 @@ void DRW_Hatch::parseCode( int code, dxfReader *reader )
else if ( ellipse ) ellipse->endparam = reader->getDouble() / ARAD;
break;
case 52:
angle = reader->getDouble();
angle = reader->getDouble() / ARAD;
break;
case 73:
if ( arc ) arc->isccw = reader->getInt32();
Expand Down Expand Up @@ -2959,10 +2960,10 @@ void DRW_Dimension::parseCode( int code, dxfReader *reader )
rot = reader->getDouble();
break;
case 50:
angle = reader->getDouble();
angle = reader->getDouble() / ARAD;
break;
case 52:
oblique = reader->getDouble();
oblique = reader->getDouble() / ARAD;
break;
case 40:
length = reader->getDouble();
Expand Down
18 changes: 3 additions & 15 deletions external/libdxfrw/intern/dxfreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,27 +282,15 @@ bool dxfReaderAscii::readInt64()

bool dxfReaderAscii::readDouble()
{
bool ok = false;
type = DOUBLE;
std::string text;
if ( readString( &text ) )
{
#if defined(__APPLE__)
int succeeded = sscanf( & ( text[0] ), "%lg", &doubleData );
if ( succeeded != 1 )
{
QgsDebugMsg( QString( "reading double error:%1" ).arg( text.c_str() ) );
}
#else
std::istringstream sd( text );
sd >> doubleData;
doubleData = QString::fromStdString( text ).toDouble( &ok );
QgsDebugMsg( QString( "%1" ).arg( doubleData ) );
#endif
return true;
}
else
{
return false;
}
return ok;
}

//saved as int or add a bool member??
Expand Down
95 changes: 61 additions & 34 deletions src/app/dwg/qgsdwgimportdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,40 +360,67 @@ void QgsDwgImportDialog::createGroup( QgsLayerTreeGroup *group, const QString &n
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::MultiLineHeight, QgsProperty::fromExpression( QStringLiteral( "CASE WHEN interlin<0 THEN 1 ELSE interlin*1.5 END" ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::PositionX, QgsProperty::fromExpression( QStringLiteral( "$x" ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::PositionY, QgsProperty::fromExpression( QStringLiteral( "$y" ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Hali, QgsProperty::fromExpression( QStringLiteral( "CASE"
" WHEN etype=%1 THEN"
" CASE"
" WHEN alignv IN (1,4,7) THEN 'Left'"
" WHEN alignv IN (2,5,6) THEN 'Center'"
" ELSE 'Right'"
" END"
" ELSE"
" CASE"
" WHEN alignh=0 THEN 'Left'"
" WHEN alignh=1 THEN 'Center'"
" WHEN alignh=2 THEN 'Right'"
" WHEN alignh=3 THEN 'Left'"
" WHEN alignh=4 THEN 'Left'"
" END "
" END" ).arg( DRW::MTEXT ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::Vali, QgsProperty::fromExpression( QStringLiteral( "CASE"
" WHEN etype=%1 THEN"
" CASE"
" WHEN alignv < 4 THEN 'Top'"
" WHEN alignv < 7 THEN 'Half'"
" ELSE 'Bottom'"
" END"
" ELSE"
" CASE"
" WHEN alignv=0 THEN 'Base'"
" WHEN alignv=1 THEN 'Bottom'"
" WHEN alignv=2 THEN 'Half'"
" WHEN alignv=3 THEN 'Top'"
" END"
" END" ).arg( DRW::MTEXT ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::LabelRotation, QgsProperty::fromExpression( QStringLiteral( "360-angle*180.0/pi()" ) ) );

pls.placement = QgsPalLayerSettings::OrderedPositionsAroundPoint;

// DXF TEXT
// vertical: 0 = Base, 1 = Bottom, 2 = Middle, 3 = Top, default Base
// horizontal: 0 = Left, 1 = Center, 2 = Right, 3 = Aligned (if Base), 4 = Middle (if Base), default Left

// DXF MTEXT
// 1 = Top left; 2 = Top center; 3 = Top right
// 4 = Middle left; 5 = Middle center; 6 = Middle right
// 7 = Bottom left; 8 = Bottom center; 9 = Bottom right

// QGIS Quadrant
// 0 QuadrantAboveLeft, 1 QuadrantAbove, 2 QuadrantAboveRight,
// 3 QuadrantLeft, 4 QuadrantOver, 5 QuadrantRight,
// 6 QuadrantBelowLeft, 7 QuadrantBelow, 8 QuadrantBelowRight,

pls.dataDefinedProperties().setProperty(
QgsPalLayerSettings::Hali,
QgsProperty::fromExpression( QStringLiteral(
"CASE"
" WHEN etype=%1 THEN"
" CASE"
" WHEN textgen % 3=2 THEN 'Center'"
" WHEN textgen % 3=0 THEN 'Right'"
" ELSE 'Left'"
" END"
" ELSE"
" CASE"
" WHEN alignh=1 THEN 'Center'"
" WHEN alignh=2 THEN 'Right'"
" ELSE 'Left'"
" END"
" END"
).arg( DRW::MTEXT )
)
);

pls.dataDefinedProperties().setProperty(
QgsPalLayerSettings::Vali,
QgsProperty::fromExpression( QStringLiteral(
"CASE"
" WHEN etype=%1 THEN"
" CASE"
" WHEN textgen<4 THEN 'Top'"
" WHEN textgen<7 THEN 'Half'"
" ELSE 'Bottom'"
" END"
" ELSE"
" CASE"
" WHEN alignv=1 THEN 'Bottom'"
" WHEN alignv=2 THEN 'Half'"
" WHEN alignv=3 THEN 'Top'"
" ELSE 'Base'"
" END"
" END"
).arg( DRW::MTEXT )
)
);

pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::LabelRotation, QgsProperty::fromExpression( QStringLiteral( "360-angle" ) ) );
pls.dataDefinedProperties().setProperty( QgsPalLayerSettings::AlwaysShow, QgsProperty::fromExpression( QStringLiteral( "1" ) ) );

l->setLabeling( new QgsVectorLayerSimpleLabeling( pls ) );
l->setLabelsEnabled( true );
}
Expand Down

0 comments on commit 92e7faa

Please sign in to comment.