Skip to content

Commit 6ea3052

Browse files
committed
odb: add dbOrientType3D class
Signed-off-by: osamahammad21 <[email protected]>
1 parent d987427 commit 6ea3052

File tree

7 files changed

+145
-24
lines changed

7 files changed

+145
-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: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,44 @@ 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+
dbOrientType3D(const char* orient);
110+
111+
///
112+
/// Create a dbOrientType3D instance with an explicit orientation.
113+
///
114+
dbOrientType3D(const dbOrientType& orient, bool mirror_z);
115+
116+
dbOrientType3D() = default;
117+
118+
///
119+
/// Copy constructor.
120+
///
121+
dbOrientType3D(const dbOrientType3D& orient) = default;
122+
123+
///
124+
/// Returns the orientation as a string
125+
///
126+
std::string getString() const;
127+
128+
dbOrientType getOrientType2D() const;
129+
130+
bool isMirrorZ() const;
131+
132+
friend dbIStream& operator>>(dbIStream& stream, dbOrientType3D& t);
133+
friend dbOStream& operator<<(dbOStream& stream, dbOrientType3D t);
134+
135+
private:
136+
dbOrientType::Value value_{dbOrientType::R0};
137+
bool mirror_z_{false};
138+
};
139+
102140
class dbGDSSTrans
103141
{
104142
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: 76 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,62 @@ 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 flipZ = false;
196+
// check if the orient string contains "MZ"
197+
if (orient_str.find("MZ_") != std::string::npos) {
198+
flipZ = true;
199+
orient_str = orient_str.erase(orient_str.find("MZ_"), 3);
200+
}
201+
auto opt = dbOrientType::fromString(orient_str.c_str());
202+
if (!opt.has_value()) {
203+
return std::nullopt;
204+
}
205+
return dbOrientType3D(opt.value(), flipZ);
206+
}
207+
208+
dbOrientType3D::dbOrientType3D(const char* orient)
209+
{
210+
auto opt = fromString(orient);
211+
if (opt.has_value()) {
212+
value_ = opt.value().value_;
213+
mirror_z_ = opt.value().mirror_z_;
214+
} else {
215+
value_ = dbOrientType::DEFAULT;
216+
mirror_z_ = false;
217+
}
218+
}
219+
220+
dbOrientType3D::dbOrientType3D(const dbOrientType& orient, bool mirror_z)
221+
{
222+
value_ = orient.getValue();
223+
mirror_z_ = mirror_z;
224+
}
225+
226+
std::string dbOrientType3D::getString() const
227+
{
228+
std::string orient_2d_str = getOrientType2D().getString();
229+
if (orient_2d_str == "MXR90") {
230+
orient_2d_str = "MX_R90";
231+
} else if (orient_2d_str == "MYR90") {
232+
orient_2d_str = "MY_R90";
233+
}
234+
return (mirror_z_ ? "MZ_" : "") + orient_2d_str;
235+
}
236+
237+
dbOrientType dbOrientType3D::getOrientType2D() const
238+
{
239+
return value_;
240+
}
241+
242+
bool dbOrientType3D::isMirrorZ() const
243+
{
244+
return mirror_z_;
245+
}
246+
189247
dbGDSSTrans::dbGDSSTrans()
190248
{
191249
_flipX = false;
@@ -269,6 +327,22 @@ dbOStream& operator<<(dbOStream& stream, const dbGDSSTrans t)
269327
return stream;
270328
}
271329

330+
dbIStream& operator>>(dbIStream& stream, dbOrientType3D& t)
331+
{
332+
uint8_t value;
333+
stream >> value;
334+
t.value_ = static_cast<dbOrientType::Value>(value);
335+
stream >> t.mirror_z_;
336+
return stream;
337+
}
338+
339+
dbOStream& operator<<(dbOStream& stream, const dbOrientType3D t)
340+
{
341+
stream << static_cast<uint8_t>(t.value_);
342+
stream << t.mirror_z_;
343+
return stream;
344+
}
345+
272346
dbIStream& operator>>(dbIStream& stream, dbGDSTextPres& t)
273347
{
274348
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)