Skip to content

Commit

Permalink
Apply Bentley Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bcs-wildman committed Oct 17, 2023
1 parent f74cd41 commit ff57ae3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
1 change: 1 addition & 0 deletions ogr/ogrsf_frmts/dwg/dgnv8_headers.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@
#include "DgSharedCellReference.h"
#include "DgText.h"
#include "DgTextNode.h"
#include "DgLevelTableRecord.h"

#endif // DGNV8_HEADERS_H
1 change: 1 addition & 0 deletions ogr/ogrsf_frmts/dwg/ogrdgnv8datasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ int OGRDGNV8DataSource::Open(const char *pszFilename, bool bUpdate)
bUpdate ? OdDg::kForWrite : OdDg::kForRead));
if (!pModel.isNull())
{
pModel->enableGlobalOriginUsage(true);
OGRDGNV8Layer *poLayer = new OGRDGNV8Layer(this, pModel);
m_papoLayers = static_cast<OGRDGNV8Layer **>(CPLRealloc(
m_papoLayers, sizeof(OGRDGNV8Layer *) * (m_nLayers + 1)));
Expand Down
49 changes: 47 additions & 2 deletions ogr/ogrsf_frmts/dwg/ogrdgnv8layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,17 @@ IsContiguous(const std::vector<tPairFeatureHoleFlag> &oVectorSubElts,
AlmostEqual(oFirstPoint.getX(), oLastPoint.getX()) &&
AlmostEqual(oFirstPoint.getY(), oLastPoint.getY()) &&
AlmostEqual(oFirstPoint.getZ(), oLastPoint.getZ());
if (bIsClosed)
{
// Make sure that the last point and the first point of the closed geometry fit exactly
// otherwise we get into errors in the processing chain

// Get the last subelement
OGRGeometry* poGeom = oVectorSubElts[oVectorSubElts.size()-1].first->GetGeometryRef();
OGRSimpleCurve* poCurve = static_cast<OGRSimpleCurve*>(poGeom);
// Set the last point of the last subelement to be idetical to the first point of the geometry
poCurve->setPoint(poCurve->getNumPoints() - 1, &oFirstPoint);
}
}
return bIsContiguous;
}
Expand Down Expand Up @@ -745,7 +756,7 @@ OGRDGNV8Layer::ProcessElement(OdDgGraphicsElementPtr element, int level)
poFeature->SetField("Level", nLevel);
poFeature->SetField("GraphicGroup",
static_cast<int>(element->getGraphicsGroupEntryId()));
const OdUInt32 uColorIndex = element->getColorIndex();
OdUInt32 uColorIndex = element->getColorIndex();
CPLString osColor;
if (uColorIndex != OdDg::kColorByLevel && uColorIndex != OdDg::kColorByCell)
{
Expand All @@ -755,13 +766,33 @@ OGRDGNV8Layer::ProcessElement(OdDgGraphicsElementPtr element, int level)
osColor = CPLSPrintf(",c:#%02x%02x%02x", ODGETRED(color),
ODGETGREEN(color), ODGETBLUE(color));
}
const OdInt32 nLineStyle = element->getLineStyleEntryId();
if (uColorIndex == OdDg::kColorByLevel)
{
OdDgLevelTableRecordPtr myLevel = OdDgLevelTableRecord::cast(element->getLevelId().openObject());
uColorIndex = myLevel->getElementColorIndex();
OdDgCmEntityColor myColor = OdDgColorTable::lookupTrueColor(element->database(), uColorIndex);
poFeature->SetField("ColorIndex",
static_cast<int>(uColorIndex));

osColor = CPLSPrintf(",c:#%02x%02x%02x",
myColor.red(),
myColor.green(),
myColor.blue());
}
OdInt32 nLineStyle = element->getLineStyleEntryId();
if (nLineStyle != OdDg::kLineStyleByLevel &&
nLineStyle != OdDg::kLineStyleByCell)
{
poFeature->SetField("Style", nLineStyle);
}

if (nLineStyle == OdDg::kLineStyleByLevel)
{
OdDgLevelTableRecordPtr myLevel = OdDgLevelTableRecord::cast(element->getLevelId().openObject());
nLineStyle = myLevel->getElementLineStyleEntryId();
poFeature->SetField("Style", nLineStyle);
}

const OdUInt32 uLineWeight = element->getLineWeight();
int nLineWeight = 0;
if (uLineWeight != OdDg::kLineWeightByLevel &&
Expand All @@ -771,6 +802,13 @@ OGRDGNV8Layer::ProcessElement(OdDgGraphicsElementPtr element, int level)
poFeature->SetField("Weight", nLineWeight);
}

if (uLineWeight == OdDg::kLineWeightByLevel)
{
OdDgLevelTableRecordPtr myLevel = OdDgLevelTableRecord::cast(element->getLevelId().openObject());
nLineWeight = static_cast<int>(myLevel->getElementLineWeight());
poFeature->SetField("Weight", nLineWeight);
}

CPLJSONObject uLinkData;
CPLJSONArray previousValues;

Expand Down Expand Up @@ -1604,6 +1642,7 @@ OGRErr OGRDGNV8Layer::DeleteFeature(GIntBig nFID)
OGRErr OGRDGNV8Layer::GetExtent(OGREnvelope *psExtent, int bForce)
{
OdDgModel::StorageUnitDescription description;
OdGePoint3d globalOrigin = m_pModel->getGlobalOrigin ();
m_pModel->getStorageUnit(description);
OdDgElementIteratorPtr iterator =
m_pModel->createGraphicsElementsIterator();
Expand Down Expand Up @@ -1648,7 +1687,13 @@ OGRErr OGRDGNV8Layer::GetExtent(OGREnvelope *psExtent, int bForce)
}
}
if (bValid)
{
psExtent->MinX -= globalOrigin.x;
psExtent->MinY -= globalOrigin.y;
psExtent->MaxX -= globalOrigin.x;
psExtent->MaxY -= globalOrigin.y;
return OGRERR_NONE;
}
return OGRLayer::GetExtent(psExtent, bForce);
}

Expand Down

0 comments on commit ff57ae3

Please sign in to comment.