23 static const bool sLazyUpdates =
false;
29 mParentWidget(nullptr),
34 mUnappliedChanges(false),
35 mSceneUpdateRequired(false),
36 mSceneUpdateInProgress(false),
37 mSpecialUpdate(false),
82 if (mUserUpdateCount == 0)
100 mRemovedModules -= old_modules;
101 mRemovedGates -= old_gates;
103 mAddedModules += new_modules;
104 mAddedGates += new_gates;
106 mPlacementList[placement.
mode()].append(
109 if (mUserUpdateCount == 0)
122 mRemovedModules += old_modules;
123 mRemovedGates += old_gates;
126 mAddedGates -=
gates;
133 if (mUserUpdateCount == 0)
143 mRemovedModules = mModules;
144 mRemovedGates = mGates;
146 mAddedModules.
clear();
149 for (
int i=0; i<4; i++)
150 mPlacementList[i].
clear();
152 if (mUserUpdateCount == 0)
161 QSet<u32> containedGates = mGates + mAddedGates - mRemovedGates;
162 return containedGates.
contains(gateId);
167 QSet<u32> containedGates = mGates + mAddedGates - mRemovedGates;
168 QSet<u32> containedModules = mModules + mAddedModules - mRemovedModules;
172 for (
const Gate*
g : m->get_gates())
174 if (!containedGates.
contains(
g->get_id()))
return false;
186 auto contained_modules = mModules + mAddedModules - mRemovedModules;
188 if (contained_modules.find(
id) != contained_modules.end())
194 Node singleContentNode;
197 for (
const Gate*
g : m->get_gates())
241 QSet<u32> tempMod = mModules + mAddedModules - mRemovedModules;
242 QSet<u32> tempGat = mGates + mAddedGates - mRemovedGates;
248 if (testIfAffectedInternal(
id, moduleId, gateId))
252 bool GraphContext::testIfAffectedInternal(
const u32 id,
const u32* moduleId,
const u32* gateId)
258 std::vector<Gate*> modifiedGates;
262 if (m) modifiedGates = m->
get_gates(
nullptr,
true);
267 if (
g) modifiedGates.push_back(
g);
269 for (Gate* mg : modifiedGates)
276 void GraphContext::removeModuleContents(
const u32 moduleId)
283 childGates.
insert(
g->get_id());
287 childModules.
insert(sm->get_id());
289 remove(childModules, childGates);
316 auto contextGates = (mGates - mRemovedGates) + mAddedGates;
317 auto contextModules = (mModules - mRemovedModules) + mAddedModules;
318 auto moduleGates = (
gates - minus_gates) + plus_gates;
319 auto moduleModules = (
modules - minus_modules) + plus_modules;
321 return contextGates == moduleGates && contextModules == moduleModules;
327 auto contextGates = (mGates - mRemovedGates) + mAddedGates;
328 if (!contextGates.isEmpty())
return false;
329 auto contextModules = (mModules - mRemovedModules) + mAddedModules;
330 if (contextModules.size() != 1)
return false;
337 auto containedModules = mModules + mAddedModules - mRemovedModules;
348 if (!containedModules.contains(sm->get_id()) &&
isModuleUnfolded(sm->get_id()))
361 if (!mExclusiveModuleId)
return false;
363 auto containedModules = mModules + mAddedModules - mRemovedModules;
364 auto containedGates = mGates + mAddedGates - mRemovedGates;
367 if (containedGates.empty() && containedModules.size() == 1 && *containedModules.begin() == mExclusiveModuleId)
378 auto src_pins =
net->get_sources();
380 for(
auto pin : src_pins)
382 if(pin->get_gate() !=
nullptr)
384 if(mGates.
contains(pin->get_gate()->get_id()))
395 auto dst_pins =
net->get_destinations();
397 for(
auto pin : dst_pins)
399 if(pin->get_gate() !=
nullptr)
401 if(mGates.
contains(pin->get_gate()->get_id()))
413 Gate*
g = ep->get_gate();
415 if (box)
return box->
getNode();
422 for (
Endpoint* ep :
n->get_destinations())
424 Gate*
g = ep->get_gate();
426 if (box)
return box->
getNode();
448 return mLayouter->
scene();
463 if (mDirty)
return mName +
"*";
469 return mSceneUpdateInProgress;
474 mSceneUpdateRequired =
true;
480 if(mUserUpdateCount == 0)
514 if (!percent) text =
QString(
"Layout %1[%2]").
arg(mName).
arg(mId);
515 if (mParentWidget) mParentWidget->
showProgress(percent,text);
532 void GraphContext::handleLayouterFinished()
534 if (mUnappliedChanges)
537 if (mSceneUpdateRequired)
539 requireSceneUpdate();
546 mSceneUpdateInProgress =
false;
554 void GraphContext::evaluateChanges()
557 mUnappliedChanges =
true;
560 void GraphContext::update()
562 if (mSceneUpdateInProgress)
567 if (mUnappliedChanges)
570 if (mSceneUpdateRequired)
571 requireSceneUpdate();
574 void GraphContext::applyChanges()
577 auto it = mAddedModules.
begin();
578 while (it != mAddedModules.
end())
583 it = mAddedModules.
erase(it);
586 mModules -= mRemovedModules;
587 mGates -= mRemovedGates;
589 mModules += mAddedModules;
590 mGates += mAddedGates;
592 mLayouter->
remove(mRemovedModules, mRemovedGates, mNets);
593 mShader->
remove(mRemovedModules, mRemovedGates, mNets);
602 for (
int iplc = 0; iplc<4; iplc++)
604 for (
const PlacementEntry& plcEntry : mPlacementList[placementOrder[iplc]])
606 QSet<u32> modsForHint = plcEntry.mModules;
607 modsForHint &= mAddedModules;
609 gatsForHint &= mAddedGates;
610 mLayouter->
add(modsForHint, gatsForHint, mNets, plcEntry.mPlacementHint);
614 mShader->
add(mAddedModules, mAddedGates, mNets);
616 mAddedModules.
clear();
619 mRemovedModules.
clear();
620 mRemovedGates.
clear();
622 for (
int i=0; i<4; i++)
623 mPlacementList[i].
clear();
625 mUnappliedChanges =
false;
626 mSceneUpdateRequired =
true;
632 for (
const auto&
id : mGates)
634 if (mRemovedGates.
contains(
id))
continue;
637 for (
auto net :
g->get_fan_in_nets())
642 for (
auto net :
g->get_fan_out_nets())
648 for (
const auto&
id : mModules)
650 if (mRemovedModules.
contains(
id))
continue;
664 void GraphContext::requireSceneUpdate()
670 void GraphContext::startSceneUpdate()
672 mSceneUpdateRequired =
false;
673 mSceneUpdateInProgress =
true;
685 handleLayouterFinished();
690 if (!mSceneUpdateInProgress)
return;
704 handleLayouterFinished();
707 void GraphContext::handleStyleChanged(
int istyle)
710 handleLayouterFinished();
719 void GraphContext::handleModuleNameChanged(
Module* m)
721 if (mExclusiveModuleId == m->
get_id())
738 if (json.
contains(
"timestamp") && json[
"timestamp"].isString())
743 if (json.
contains(
"modules") && json[
"modules"].isArray())
745 QJsonArray jsonMods = json[
"modules"].toArray();
746 int nmods = jsonMods.
size();
747 for (
int imod=0; imod<nmods; imod++)
750 if (!jsonMod.
contains(
"id") || !jsonMod[
"id"].isDouble())
continue;
751 u32 id = jsonMod[
"id"].toInt();
754 log_warning(
"gui",
"Module id={} not found in netlist, view id={} not restored.",
id, mId);
757 if (!jsonMod.
contains(
"x") || !jsonMod[
"x"].isDouble())
continue;
758 int x = jsonMod[
"x"].toInt();
759 if (!jsonMod.
contains(
"y") || !jsonMod[
"y"].isDouble())
continue;
760 int y = jsonMod[
"y"].toInt();
766 if (json.
contains(
"gates") && json[
"gates"].isArray())
768 QJsonArray jsonGats = json[
"gates"].toArray();
769 int ngats = jsonGats.
size();
770 for (
int igat=0; igat<ngats; igat++)
773 if (!jsonGat.
contains(
"id") || !jsonGat[
"id"].isDouble())
continue;
774 u32 id = jsonGat[
"id"].toInt();
777 log_warning(
"gui",
"Gate id={} not found in netlist, view id={} not restored.",
id, mId);
780 if (!jsonGat.
contains(
"x") || !jsonGat[
"x"].isDouble())
continue;
781 int x = jsonGat[
"x"].toInt();
782 if (!jsonGat.
contains(
"y") || !jsonGat[
"y"].isDouble())
continue;
783 int y = jsonGat[
"y"].toInt();
791 log_warning(
"gui",
"Cannot restore view id={}, there are no nodes to place.", mId);
800 mModules.
insert(box.first.id());
802 mGates.
insert(box.first.id());
808 if (json.
contains(
"nets") && json[
"nets"].isArray())
811 int nnets = jsonNets.
size();
812 for (
int inet=0; inet<nnets; inet++)
815 if (!jsonNet.
contains(
"id") || !jsonNet[
"id"].isDouble())
continue;
816 u32 id = jsonNet[
"id"].toInt();
829 json[
"id"] = (int) mId;
830 json[
"name"] = mName;
831 json[
"timestamp"] = mTimestamp.
toString();
832 json[
"exclusiveModuleId"] = (int) mExclusiveModuleId;
834 json[
"parentId"] = (int) parentId;
837 for (
u32 id : mModules)
842 jsonMod[
"id"] = (int)
id;
843 jsonMod[
"x"] = (int) pos.
x();
844 jsonMod[
"y"] = (int) pos.
y();
847 json[
"modules"] = jsonMods;
851 for (
u32 id : mGates)
856 jsonGat[
"id"] = (int)
id;
857 jsonGat[
"x"] = (int) pos.
x();
858 jsonGat[
"y"] = (int) pos.
y();
861 json[
"gates"] = jsonGats;
868 jsonNet[
"id"] = (int)
id;
871 json[
"nets"] = jsonNets;
877 if (mDirty==dty)
return;
884 mScheduleRemoveModules = mods;
885 mScheduleRemoveGates = gats;
893 auto it = mScheduleRemoveModules.
find(nd.
id());
894 if (it != mScheduleRemoveModules.
end())
896 mScheduleRemoveModules.
erase(it);
903 auto it = mScheduleRemoveGates.
find(nd.
id());
904 if (it != mScheduleRemoveGates.
end())
906 mScheduleRemoveGates.
erase(it);
919 mSpecialUpdate =
state;
930 u32 old_id = mExclusiveModuleId;
931 mExclusiveModuleId =
id;
934 if ((
id == 0 && old_id != 0) && emitSignal)
938 void GraphContext::handleExclusiveModuleLost(
u32 old_id)
955 if (ctx->name() == new_name)
963 ActionRenameObject* act =
new ActionRenameObject(new_name);
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for and distribution as defined by Sections through of this document Licensor shall mean the copyright owner or entity authorized by the copyright owner that is granting the License Legal Entity shall mean the union of the acting entity and all other entities that control are controlled by or are under common control with that entity For the purposes of this definition control direct or to cause the direction or management of such whether by contract or including but not limited to software source documentation and configuration files Object form shall mean any form resulting from mechanical transformation or translation of a Source including but not limited to compiled object generated and conversions to other media types Work shall mean the work of whether in Source or Object made available under the as indicated by a copyright notice that is included in or attached to the whether in Source or Object that is based or other modifications as a an original work of authorship For the purposes of this Derivative Works shall not include works that remain separable from
GraphTabWidget * getGraphTabWidget()
Get hal's graph tab widget.
bool isModuleUnfolded(const u32 moduleId) const
bool isGateUnfolded(u32 gateId) const
void remove(const QSet< u32 > &modules, const QSet< u32 > &gates)
void setSpecialUpdate(bool state)
void writeToFile(QJsonObject &json, int parentId)
void unfoldModule(const u32 id, const PlacementHint &plc)
void showComments(const Node &nd)
void exclusiveModuleCheck()
bool readFromFile(const QJsonObject &json)
Node getNetSource(const Net *n) const
bool isShowingModuleExclusively()
void moveNodeAction(const QPoint &from, const QPoint &to)
bool isShowingFoldedTopModule() const
bool isShowingModule(const u32 id) const
void setExclusiveModuleId(u32 id, bool emitSignal=true)
void add(const QSet< u32 > &modules, const QSet< u32 > &gates, PlacementHint placement=PlacementHint())
void layoutProgress(int percent) const
Node getNetDestination(const Net *n) const
const QSet< u32 > & gates() const
const QSet< u32 > & modules() const
void testIfAffected(const u32 id, const u32 *moduleId, const u32 *gateId)
Node nodeForGate(const u32 id) const
void exclusiveModuleLost(u32 old_id)
void scheduleSceneUpdate()
void setScheduleRemove(const QSet< u32 > &mods, const QSet< u32 > &gats)
void setShader(GraphShader *shader)
bool isScheduledRemove(const Node &nd)
QDateTime getTimestamp() const
GraphLayouter * getLayouter() const
GraphContext(u32 id_, const QString &name, QObject *parent=nullptr)
bool willBeEmptied() const
QString getNameWithDirtyState() const
void setLayouter(GraphLayouter *layouter)
const QSet< u32 > & nets() const
bool isShowingNetSource(const u32 mNetId) const
bool sceneUpdateInProgress() const
bool isShowingNetDestination(const u32 mNetId) const
void getModuleChildrenRecursively(const u32 moduleId, QSet< u32 > *gates, QSet< u32 > *modules) const
QVector< GraphContext * > getContexts() const
Base class for all specific layouters.
virtual void remove(const QSet< u32 > modules, const QSet< u32 > gates, const QSet< u32 > nets)=0
void setNodePosition(const Node &n, const QPoint &p)
virtual void add(const QSet< u32 > modules, const QSet< u32 > gates, const QSet< u32 > nets, PlacementHint placement=PlacementHint())=0
const QMap< QPoint, Node > positionToNodeMap() const
NetLayoutPoint positonForNode(const Node &nd) const
const QMap< Node, QPoint > nodeToPositionMap() const
GraphicsScene * scene() const
const NodeBoxes & boxes() const
Base class to store and update visual information about the graph.
virtual void add(const QSet< u32 > modules, const QSet< u32 > gates, const QSet< u32 > nets)=0
virtual void remove(const QSet< u32 > modules, const QSet< u32 > gates, const QSet< u32 > nets)=0
const Shading & getShading()
Container for a GraphGraphicsView containing gates, nets, and modules.
void updateVisuals(const GraphShader::Shading &s)
static LayoutLockerManager * instance()
void removeWaitingContext(GraphContext *ctx)
static SettingsItemDropdown * sSettingStyle
Module * get_parent_module() const
const std::vector< Gate * > & get_gates() const
std::string get_name() const
const std::unordered_set< Net * > & get_input_nets() const
std::vector< Module * > get_submodules(const std::function< bool(Module *)> &filter=nullptr, bool recursive=false) const
const std::unordered_set< Net * > & get_output_nets() const
Gate * get_gate_by_id(const u32 gate_id) const
Module * get_module_by_id(u32 module_id) const
Net * get_net_by_id(u32 net_id) const
void moduleNameChanged(Module *m) const
The NodeBox class represents a node placed at a grid position within a hal view.
Node getNode() const
getNode getter for node information
NodeBox * boxForGate(const Gate *g) const
boxForGate find NodeBox by Gate pointer.
The Node class object represents a module or a gate.
NodeType type() const
type getter for type information
u32 id() const
id getter for ID information
Container class to store a PlacementHint togerther with a set of modules and gates.
The PlacementHint class object provides hints for the layouter how new box objects are placed on a vi...
void addGridPosition(const Node &nd, const QPoint &p)
PlacementModeType mode() const
mode getter for placement mode type
void intChanged(int value)
virtual void setObject(const UserActionObject &obj)
The UserActionObject class represents a single object used in UserAction.
#define log_warning(channel,...)
ContentManager * gContentManager
GraphContextManager * gGraphContextManager
NetlistRelay * gNetlistRelay
QDateTime currentDateTime()
QDateTime fromString(const QString &string, Qt::DateFormat format)
QString toString(Qt::DateFormat format) const const
void append(const QJsonValue &value)
QJsonValue at(int i) const const
bool contains(const QString &key) const const
QJsonObject toObject() const const
void append(const T &value)
bool isEmpty() const const
QMap::const_iterator constEnd() const const
QMap::iterator find(const Key &key)
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QSet::const_iterator constBegin() const const
bool contains(const T &value) const const
QSet::iterator erase(QSet::iterator pos)
QSet::iterator find(const T &value)
QSet::iterator insert(const T &value)
bool isEmpty() const const
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromStdString(const std::string &str)
QString number(int n, int base)