Skip to content

Commit 6795ef1

Browse files
Merge pull request #8263 from osamahammad21/odb-dbOrientType3D
ODB: add dbOrientType3D class
2 parents 0575333 + 7f6bf22 commit 6795ef1

File tree

7 files changed

+149
-24
lines changed

7 files changed

+149
-24
lines changed

src/odb/include/odb/db.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7120,14 +7120,15 @@ class dbChipInst : public dbObject
71207120

71217121
Point3D getLoc() const;
71227122

7123+
void setOrient(dbOrientType3D orient);
7124+
7125+
dbOrientType3D getOrient() const;
7126+
71237127
dbChip* getMasterChip() const;
71247128

71257129
dbChip* getParentChip() const;
71267130

71277131
// User Code Begin dbChipInst
7128-
void setOrient(const dbOrientType& orient);
7129-
7130-
dbOrientType getOrient() const;
71317132

71327133
dbTransform getTransform() const;
71337134

src/odb/include/odb/dbTypes.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,42 @@ class dbOrientType
9999
Value _value;
100100
};
101101

102+
class dbOrientType3D
103+
{
104+
public:
105+
static std::optional<dbOrientType3D> fromString(const std::string& orient);
106+
107+
dbOrientType3D(const std::string& orient);
108+
109+
///
110+
/// Create a dbOrientType3D instance with an explicit orientation.
111+
///
112+
dbOrientType3D(const dbOrientType& orient, bool mirror_z);
113+
114+
dbOrientType3D() = default;
115+
116+
///
117+
/// Copy constructor.
118+
///
119+
dbOrientType3D(const dbOrientType3D& orient) = default;
120+
121+
///
122+
/// Returns the orientation as a string
123+
///
124+
std::string getString() const;
125+
126+
dbOrientType getOrientType2D() const;
127+
128+
bool isMirrorZ() const;
129+
130+
friend dbIStream& operator>>(dbIStream& stream, dbOrientType3D& t);
131+
friend dbOStream& operator<<(dbOStream& stream, dbOrientType3D t);
132+
133+
private:
134+
dbOrientType::Value value_{dbOrientType::R0};
135+
bool mirror_z_{false};
136+
};
137+
102138
class dbGDSSTrans
103139
{
104140
public:

src/odb/src/codeGenerator/schema/chip/dbChipInst.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
},
1515
{
1616
"name": "orient_",
17-
"type": "dbOrientType::Value",
18-
"flags": ["private" ,"cmpgt", "no-serial"],
19-
"default": "dbOrientType::R0"
17+
"type": "dbOrientType3D",
18+
"flags": []
2019
},
2120
{
2221
"name": "master_chip_",

src/odb/src/db/dbChipInst.cpp

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ bool _dbChipInst::operator<(const _dbChipInst& rhs) const
5858

5959
_dbChipInst::_dbChipInst(_dbDatabase* db)
6060
{
61-
orient_ = dbOrientType::R0;
6261
}
6362

6463
dbIStream& operator>>(dbIStream& stream, _dbChipInst& obj)
6564
{
6665
stream >> obj.name_;
6766
stream >> obj.loc_;
67+
stream >> obj.orient_;
6868
stream >> obj.master_chip_;
6969
stream >> obj.parent_chip_;
7070
stream >> obj.chipinst_next_;
@@ -78,6 +78,7 @@ dbOStream& operator<<(dbOStream& stream, const _dbChipInst& obj)
7878
{
7979
stream << obj.name_;
8080
stream << obj.loc_;
81+
stream << obj.orient_;
8182
stream << obj.master_chip_;
8283
stream << obj.parent_chip_;
8384
stream << obj.chipinst_next_;
@@ -116,6 +117,19 @@ Point3D dbChipInst::getLoc() const
116117
return obj->loc_;
117118
}
118119

120+
void dbChipInst::setOrient(dbOrientType3D orient)
121+
{
122+
_dbChipInst* obj = (_dbChipInst*) this;
123+
124+
obj->orient_ = orient;
125+
}
126+
127+
dbOrientType3D dbChipInst::getOrient() const
128+
{
129+
_dbChipInst* obj = (_dbChipInst*) this;
130+
return obj->orient_;
131+
}
132+
119133
dbChip* dbChipInst::getMasterChip() const
120134
{
121135
_dbChipInst* obj = (_dbChipInst*) this;
@@ -137,23 +151,13 @@ dbChip* dbChipInst::getParentChip() const
137151
}
138152

139153
// User Code Begin dbChipInstPublicMethods
140-
void dbChipInst::setOrient(const dbOrientType& orient)
141-
{
142-
_dbChipInst* obj = (_dbChipInst*) this;
143-
obj->orient_ = orient;
144-
}
145-
146-
dbOrientType dbChipInst::getOrient() const
147-
{
148-
_dbChipInst* obj = (_dbChipInst*) this;
149-
return obj->orient_;
150-
}
151154

152155
dbTransform dbChipInst::getTransform() const
153156
{
154157
_dbChipInst* obj = (_dbChipInst*) this;
155158
// TODO: Add 3d Point handling to the transform
156-
return dbTransform(obj->orient_, Point(obj->loc_.x(), obj->loc_.y()));
159+
return dbTransform(obj->orient_.getOrientType2D(),
160+
Point(obj->loc_.x(), obj->loc_.y()));
157161
}
158162

159163
dbSet<dbChipRegionInst> dbChipInst::getRegions() const
@@ -219,8 +223,6 @@ dbChipInst* dbChipInst::create(dbChip* parent_chip,
219223
// Initialize the chip instance
220224
chipinst->name_ = name;
221225
chipinst->loc_ = Point3D(0, 0, 0); // Default location
222-
chipinst->orient_
223-
= dbOrientType::R0; // Default orientation (already set in constructor)
224226
chipinst->master_chip_ = _master->getOID();
225227
chipinst->parent_chip_ = _parent->getOID();
226228

src/odb/src/db/dbChipInst.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class _dbChipInst : public _dbObject
3434

3535
std::string name_;
3636
Point3D loc_;
37-
dbOrientType::Value orient_;
37+
dbOrientType3D orient_;
3838
dbId<_dbChip> master_chip_;
3939
dbId<_dbChip> parent_chip_;
4040
dbId<_dbChipInst> chipinst_next_;

src/odb/src/db/dbTypes.cpp

Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ std::optional<dbOrientType::Value> dbOrientType::fromString(const char* orient)
3030
ret = R270;
3131
} else if (strcasecmp(orient, "MY") == 0) {
3232
ret = MY;
33-
} else if (strcasecmp(orient, "MYR90") == 0) {
33+
} else if (strcasecmp(orient, "MYR90") == 0
34+
|| strcasecmp(orient, "MY_R90") == 0) {
3435
ret = MYR90;
3536
} else if (strcasecmp(orient, "MX") == 0) {
3637
ret = MX;
37-
} else if (strcasecmp(orient, "MXR90") == 0) {
38+
} else if (strcasecmp(orient, "MXR90") == 0
39+
|| strcasecmp(orient, "MX_R90") == 0) {
3840
ret = MXR90;
3941
} else if (strcasecmp(orient, "N") == 0) { // LEF/DEF style names
4042
ret = R0;
@@ -186,6 +188,68 @@ bool dbOrientType::isRightAngleRotation() const
186188
return false;
187189
}
188190

191+
std::optional<dbOrientType3D> dbOrientType3D::fromString(
192+
const std::string& orient)
193+
{
194+
std::string orient_str = orient;
195+
bool mirror_z = false;
196+
// check if the orient string contains "MZ"
197+
if (orient_str == "MZ") {
198+
return dbOrientType3D(dbOrientType::R0, true);
199+
}
200+
if (orient_str.find("MZ_") != std::string::npos) {
201+
mirror_z = true;
202+
orient_str = orient_str.erase(orient_str.find("MZ_"), 3);
203+
}
204+
auto opt = dbOrientType::fromString(orient_str.c_str());
205+
if (!opt.has_value()) {
206+
return std::nullopt;
207+
}
208+
return dbOrientType3D(opt.value(), mirror_z);
209+
}
210+
211+
dbOrientType3D::dbOrientType3D(const std::string& orient)
212+
{
213+
auto opt = fromString(orient);
214+
if (opt.has_value()) {
215+
value_ = opt.value().value_;
216+
mirror_z_ = opt.value().mirror_z_;
217+
} else {
218+
value_ = dbOrientType::DEFAULT;
219+
mirror_z_ = false;
220+
}
221+
}
222+
223+
dbOrientType3D::dbOrientType3D(const dbOrientType& orient, bool mirror_z)
224+
{
225+
value_ = orient.getValue();
226+
mirror_z_ = mirror_z;
227+
}
228+
229+
std::string dbOrientType3D::getString() const
230+
{
231+
if (mirror_z_ && getOrientType2D() == dbOrientType::R0) {
232+
return "MZ";
233+
}
234+
std::string orient_2d_str = getOrientType2D().getString();
235+
if (orient_2d_str == "MXR90") {
236+
orient_2d_str = "MX_R90";
237+
} else if (orient_2d_str == "MYR90") {
238+
orient_2d_str = "MY_R90";
239+
}
240+
return (mirror_z_ ? "MZ_" : "") + orient_2d_str;
241+
}
242+
243+
dbOrientType dbOrientType3D::getOrientType2D() const
244+
{
245+
return value_;
246+
}
247+
248+
bool dbOrientType3D::isMirrorZ() const
249+
{
250+
return mirror_z_;
251+
}
252+
189253
dbGDSSTrans::dbGDSSTrans()
190254
{
191255
_flipX = false;
@@ -269,6 +333,22 @@ dbOStream& operator<<(dbOStream& stream, const dbGDSSTrans t)
269333
return stream;
270334
}
271335

336+
dbIStream& operator>>(dbIStream& stream, dbOrientType3D& t)
337+
{
338+
uint8_t value;
339+
stream >> value;
340+
t.value_ = static_cast<dbOrientType::Value>(value);
341+
stream >> t.mirror_z_;
342+
return stream;
343+
}
344+
345+
dbOStream& operator<<(dbOStream& stream, const dbOrientType3D t)
346+
{
347+
stream << static_cast<uint8_t>(t.value_);
348+
stream << t.mirror_z_;
349+
return stream;
350+
}
351+
272352
dbIStream& operator>>(dbIStream& stream, dbGDSTextPres& t)
273353
{
274354
uint8_t vPresTemp, hPresTemp;

src/odb/test/cpp/TestChips.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ struct F_CHIP_HIERARCHY
8080
// Position components
8181
memory_inst->setLoc(Point3D(2500, 500, 0));
8282
cache_inst->setLoc(Point3D(100, 100, 50));
83+
cache_inst->setOrient(dbOrientType3D("MZ_MY_R90"));
8384
}
8485

8586
~F_CHIP_HIERARCHY() { dbDatabase::destroy(db); }
@@ -191,11 +192,17 @@ BOOST_FIXTURE_TEST_CASE(test_chip_hierarchy, F_CHIP_HIERARCHY)
191192
BOOST_TEST(memory_loc.x() == 2500);
192193
BOOST_TEST(memory_loc.y() == 500);
193194
BOOST_TEST(memory_loc.z() == 0);
195+
BOOST_TEST(memory_inst->getOrient().getOrientType2D() == dbOrientType::R0);
196+
BOOST_TEST(memory_inst->getOrient().isMirrorZ() == false);
197+
BOOST_TEST(memory_inst->getOrient().getString() == "R0");
194198

195199
Point3D cache_loc = cache_inst->getLoc();
196200
BOOST_TEST(cache_loc.x() == 100);
197201
BOOST_TEST(cache_loc.y() == 100);
198202
BOOST_TEST(cache_loc.z() == 50);
203+
BOOST_TEST(cache_inst->getOrient().getOrientType2D() == dbOrientType::MYR90);
204+
BOOST_TEST(cache_inst->getOrient().isMirrorZ() == true);
205+
BOOST_TEST(cache_inst->getOrient().getString() == "MZ_MY_R90");
199206
}
200207

201208
BOOST_FIXTURE_TEST_CASE(test_chip_complex_destroy, F_CHIP_HIERARCHY)

0 commit comments

Comments
 (0)