ZLayout EDA Library v1.0.0
Advanced Electronic Design Automation Layout Library with Bilingual Documentation
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <memory>
12#include <vector>
13#include <string>
14#include <map>
15#include <unordered_map>
16#include <functional>
19
20namespace zlayout {
21namespace components {
22
23// Forward declarations
24class Component;
25class Pin;
26class Net;
28
32enum class PinType {
33 Input, // Signal input
34 Output, // Signal output
35 Bidirectional, // Bidirectional signal
36 Power, // Power supply
37 Ground, // Ground
38 Clock, // Clock signal
39 Reset, // Reset signal
40 Analog // Analog signal
41};
42
46enum class SignalState {
47 Low = 0, // Logic 0
48 High = 1, // Logic 1
49 Unknown = 2, // Unknown state
50 HighZ = 3 // High impedance
51};
52
57 Passive, // R, L, C
58 Active, // Diodes, Transistors
59 Digital, // Logic gates, Flip-flops
60 Analog, // Op-amps, Comparators
61 Mixed, // ADC, DAC
62 Memory, // SRAM, DRAM, Flash
63 Processor, // CPU, GPU, DSP
64 Interface, // I/O, Communication
65 Power, // Regulators, Converters
66 Custom // User-defined
67};
68
72enum class TechNode {
73 um_180 = 180, // 180nm
74 um_130 = 130, // 130nm
75 um_90 = 90, // 90nm
76 um_65 = 65, // 65nm
77 um_45 = 45, // 45nm
78 um_32 = 32, // 32nm
79 um_22 = 22, // 22nm
80 um_14 = 14, // 14nm
81 um_10 = 10, // 10nm
82 um_7 = 7, // 7nm
83 um_5 = 5, // 5nm
84 um_3 = 3, // 3nm
85 um_2 = 2 // 2nm
86};
87
91class Pin {
92public:
93 Pin(const std::string& name, PinType type, const geometry::Point& position);
94
95 // Getters
96 const std::string& getName() const { return name_; }
97 PinType getType() const { return type_; }
98 const geometry::Point& getPosition() const { return position_; }
99 SignalState getSignalState() const { return signal_state_; }
100
101 // Setters
102 void setSignalState(SignalState state) { signal_state_ = state; }
103 void setPosition(const geometry::Point& pos) { position_ = pos; }
104
105 // Connection management
106 void connectToNet(std::shared_ptr<Net> net);
108 std::shared_ptr<Net> getNet() const { return net_; }
109 bool isConnected() const { return net_ != nullptr; }
110
111private:
112 std::string name_;
113 PinType type_;
114 geometry::Point position_;
115 SignalState signal_state_ = SignalState::Unknown;
116 std::shared_ptr<Net> net_;
117};
118
122class Net {
123public:
124 explicit Net(const std::string& name);
125
126 const std::string& getName() const { return name_; }
127
128 // Pin management
129 void addPin(std::shared_ptr<Pin> pin);
130 void removePin(std::shared_ptr<Pin> pin);
131 const std::vector<std::shared_ptr<Pin>>& getPins() const { return pins_; }
132
133 // Signal propagation
135
136private:
137 std::string name_;
138 std::vector<std::shared_ptr<Pin>> pins_;
139};
140
145 double propagation_delay = 0.0; // ns
146 double setup_time = 0.0; // ns
147 double hold_time = 0.0; // ns
148 double clock_to_q = 0.0; // ns
149 double max_frequency = 0.0; // MHz
150};
151
155struct PowerInfo {
156 double static_power = 0.0; // μW
157 double dynamic_power = 0.0; // μW per MHz
158 double leakage_current = 0.0; // nA
159 double supply_voltage = 0.0; // V
160 double threshold_voltage = 0.0; // V
161};
162
167 double resistance = 0.0; // Ω
168 double capacitance = 0.0; // pF
169 double inductance = 0.0; // nH
170 double current_rating = 0.0; // mA
171 double voltage_rating = 0.0; // V
172 double tolerance = 0.0; // %
173};
174
179public:
180 Component(const std::string& name, ComponentCategory category);
181 virtual ~Component() = default;
182
183 // Basic information
184 const std::string& getName() const { return name_; }
185 const std::string& getType() const { return type_; }
187
188 void setName(const std::string& name) { name_ = name; }
189 void setType(const std::string& type) { type_ = type; }
190
191 // Hierarchical structure
192 void addChild(std::shared_ptr<Component> child);
193 void removeChild(const std::string& name);
194 std::shared_ptr<Component> getChild(const std::string& name) const;
195 const std::vector<std::shared_ptr<Component>>& getChildren() const { return children_; }
196
197 std::shared_ptr<Component> getParent() const { return parent_.lock(); }
198 void setParent(std::shared_ptr<Component> parent) { parent_ = parent; }
199
200 // Geometry
203
205 void setPosition(const geometry::Point& pos) { position_ = pos; }
206
207 double getRotation() const { return rotation_; }
208 void setRotation(double angle) { rotation_ = angle; }
209
210 // Pin management
211 void addPin(std::shared_ptr<Pin> pin);
212 void removePin(const std::string& name);
213 std::shared_ptr<Pin> getPin(const std::string& name) const;
214 const std::vector<std::shared_ptr<Pin>>& getPins() const { return pins_; }
215
216 // Properties
217 void setProperty(const std::string& key, const std::string& value);
218 std::string getProperty(const std::string& key) const;
219 const std::map<std::string, std::string>& getProperties() const { return properties_; }
220
221 // Characteristics
222 void setTimingInfo(const TimingInfo& timing) { timing_ = timing; }
223 const TimingInfo& getTimingInfo() const { return timing_; }
224
225 void setPowerInfo(const PowerInfo& power) { power_ = power; }
226 const PowerInfo& getPowerInfo() const { return power_; }
227
228 void setElectricalInfo(const ElectricalInfo& electrical) { electrical_ = electrical; }
230
231 void setTechNode(TechNode node) { tech_node_ = node; }
232 TechNode getTechNode() const { return tech_node_; }
233
234 // Virtual methods for derived classes
235 virtual void simulate(double time_step) {}
236 virtual void reset() {}
237 virtual std::string getDescription() const { return "Generic Component"; }
238
239 // Hierarchical optimization support
241 virtual double calculateTotalArea() const;
242 virtual size_t getTotalGateCount() const;
243 virtual std::vector<std::shared_ptr<Component>> flattenHierarchy() const;
244
245 // Serialization
246 virtual std::string serialize() const;
247 virtual void deserialize(const std::string& data);
248
249protected:
250 std::string name_;
251 std::string type_;
253
254 // Hierarchical structure
255 std::vector<std::shared_ptr<Component>> children_;
256 std::weak_ptr<Component> parent_;
257
258 // Geometry
261 double rotation_ = 0.0;
262
263 // Pins
264 std::vector<std::shared_ptr<Pin>> pins_;
265 std::unordered_map<std::string, std::shared_ptr<Pin>> pin_map_;
266
267 // Properties
268 std::map<std::string, std::string> properties_;
269
270 // Characteristics
275};
276
281public:
282 ComponentLibrary(const std::string& name);
283
284 // Component management
285 void addComponent(std::shared_ptr<Component> component);
286 std::shared_ptr<Component> getComponent(const std::string& name) const;
287 std::shared_ptr<Component> createComponent(const std::string& type, const std::string& name) const;
288
289 // Library information
290 const std::string& getName() const { return name_; }
291 std::vector<std::string> getComponentTypes() const;
292
293 // Serialization
294 void saveToFile(const std::string& filename) const;
295 void loadFromFile(const std::string& filename);
296
297private:
298 std::string name_;
299 std::unordered_map<std::string, std::shared_ptr<Component>> components_;
300 std::unordered_map<std::string, std::function<std::shared_ptr<Component>(const std::string&)>> factories_;
301};
302
306namespace ComponentUtils {
307 // Hierarchy traversal
308 void traversePreOrder(std::shared_ptr<Component> root,
309 std::function<void(std::shared_ptr<Component>)> visitor);
310 void traversePostOrder(std::shared_ptr<Component> root,
311 std::function<void(std::shared_ptr<Component>)> visitor);
312
313 // Component analysis
314 size_t countComponents(std::shared_ptr<Component> root, ComponentCategory category);
315 double calculateTotalPower(std::shared_ptr<Component> root);
316 double calculateCriticalPath(std::shared_ptr<Component> root);
317
318 // Hierarchy optimization
319 std::vector<std::shared_ptr<Component>> groupComponentsByFunction(
320 const std::vector<std::shared_ptr<Component>>& components);
321
322 std::shared_ptr<Component> createHierarchicalBlock(
323 const std::vector<std::shared_ptr<Component>>& components,
324 const std::string& block_name);
325}
326
327} // namespace components
328} // namespace zlayout
Base class for all EDA components.
std::vector< std::shared_ptr< Component > > children_
const geometry::Rectangle & getBoundingBox() const
ComponentCategory getCategory() const
void addPin(std::shared_ptr< Pin > pin)
const std::string & getType() const
void setPosition(const geometry::Point &pos)
void setElectricalInfo(const ElectricalInfo &electrical)
virtual size_t getTotalGateCount() const
std::string getProperty(const std::string &key) const
virtual void deserialize(const std::string &data)
void removePin(const std::string &name)
void setTechNode(TechNode node)
void removeChild(const std::string &name)
std::weak_ptr< Component > parent_
virtual std::string getDescription() const
geometry::Point getPosition() const
virtual geometry::Rectangle calculateHierarchicalBoundingBox() const
void setRotation(double angle)
const TimingInfo & getTimingInfo() const
virtual std::vector< std::shared_ptr< Component > > flattenHierarchy() const
void setTimingInfo(const TimingInfo &timing)
std::shared_ptr< Component > getParent() const
const std::vector< std::shared_ptr< Pin > > & getPins() const
void setType(const std::string &type)
const std::string & getName() const
const std::vector< std::shared_ptr< Component > > & getChildren() const
const std::map< std::string, std::string > & getProperties() const
virtual double calculateTotalArea() const
const ElectricalInfo & getElectricalInfo() const
void addChild(std::shared_ptr< Component > child)
Component(const std::string &name, ComponentCategory category)
std::shared_ptr< Pin > getPin(const std::string &name) const
void setParent(std::shared_ptr< Component > parent)
void setProperty(const std::string &key, const std::string &value)
virtual ~Component()=default
void setPowerInfo(const PowerInfo &power)
std::unordered_map< std::string, std::shared_ptr< Pin > > pin_map_
void setBoundingBox(const geometry::Rectangle &bbox)
geometry::Rectangle bounding_box_
virtual void simulate(double time_step)
std::shared_ptr< Component > getChild(const std::string &name) const
std::vector< std::shared_ptr< Pin > > pins_
virtual std::string serialize() const
std::map< std::string, std::string > properties_
void setName(const std::string &name)
const PowerInfo & getPowerInfo() const
Component library for managing component definitions.
void addComponent(std::shared_ptr< Component > component)
ComponentLibrary(const std::string &name)
std::vector< std::string > getComponentTypes() const
const std::string & getName() const
void loadFromFile(const std::string &filename)
std::shared_ptr< Component > getComponent(const std::string &name) const
void saveToFile(const std::string &filename) const
std::shared_ptr< Component > createComponent(const std::string &type, const std::string &name) const
Memory component (RAM/ROM)
Net class representing electrical connections.
const std::string & getName() const
Net(const std::string &name)
const std::vector< std::shared_ptr< Pin > > & getPins() const
void propagateSignal(SignalState state)
void addPin(std::shared_ptr< Pin > pin)
void removePin(std::shared_ptr< Pin > pin)
Pin class representing component connection points.
Definition component.hpp:91
Pin(const std::string &name, PinType type, const geometry::Point &position)
const geometry::Point & getPosition() const
Definition component.hpp:98
void connectToNet(std::shared_ptr< Net > net)
std::shared_ptr< Net > getNet() const
void setPosition(const geometry::Point &pos)
void setSignalState(SignalState state)
const std::string & getName() const
Definition component.hpp:96
SignalState getSignalState() const
Definition component.hpp:99
PinType getType() const
Definition component.hpp:97
2D point with high-precision coordinates and utility methods
Definition point.hpp:23
Axis-aligned rectangle for bounding boxes and simple EDA components.
Definition rectangle.hpp:26
Utility functions for component hierarchy.
void traversePostOrder(std::shared_ptr< Component > root, std::function< void(std::shared_ptr< Component >)> visitor)
size_t countComponents(std::shared_ptr< Component > root, ComponentCategory category)
double calculateTotalPower(std::shared_ptr< Component > root)
void traversePreOrder(std::shared_ptr< Component > root, std::function< void(std::shared_ptr< Component >)> visitor)
std::shared_ptr< Component > createHierarchicalBlock(const std::vector< std::shared_ptr< Component > > &components, const std::string &block_name)
double calculateCriticalPath(std::shared_ptr< Component > root)
std::vector< std::shared_ptr< Component > > groupComponentsByFunction(const std::vector< std::shared_ptr< Component > > &components)
PinType
Pin types for component connections.
Definition component.hpp:32
SignalState
Signal states in digital circuits.
Definition component.hpp:46
ComponentCategory
Component categories for organization.
Definition component.hpp:56
TechNode
Technology nodes for manufacturing.
Definition component.hpp:72
Main namespace for ZLayout library.
Definition component.hpp:20
2D Point class for geometric calculations
Axis-aligned rectangle class for bounding boxes and simple components.
Component electrical characteristics.
Component power information.
Component timing information.