summaryrefslogtreecommitdiffstats
path: root/src/electronics/components/ecsubcircuit.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/electronics/components/ecsubcircuit.cpp')
-rw-r--r--src/electronics/components/ecsubcircuit.cpp130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/electronics/components/ecsubcircuit.cpp b/src/electronics/components/ecsubcircuit.cpp
new file mode 100644
index 0000000..a69e720
--- /dev/null
+++ b/src/electronics/components/ecsubcircuit.cpp
@@ -0,0 +1,130 @@
+/***************************************************************************
+ * Copyright (C) 2005 by David Saxton *
+ * david@bluehaze.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ ***************************************************************************/
+
+#include "canvasitemparts.h"
+#include "circuitdocument.h"
+#include "ecsubcircuit.h"
+#include "node.h"
+#include "libraryitem.h"
+#include "subcircuits.h"
+
+#include <kdebug.h>
+#include <klocale.h>
+#include <qfile.h>
+
+Item* ECSubcircuit::construct( ItemDocument *itemDocument, bool newItem, const char *id )
+{
+ return new ECSubcircuit( (ICNDocument*)itemDocument, newItem, id );
+}
+
+LibraryItem* ECSubcircuit::libraryItem()
+{
+ return new LibraryItem(
+ QString::QString("ec/subcircuit"),
+ QString::null,
+ QString::null,
+ QString::null,
+ LibraryItem::lit_subcircuit,
+ ECSubcircuit::construct );
+}
+
+ECSubcircuit::ECSubcircuit( ICNDocument *icnDocument, bool newItem, const char *id )
+ : Component( icnDocument, newItem, (id) ? id : "subcircuit" )
+{
+ m_name = i18n("Subcircuit");
+
+ createProperty( "id", Variant::Type::Int );
+ property("id")->setMinValue(1);
+ property("id")->setMaxValue(1<<15);
+ property("id")->setValue(1);
+ property("id")->setHidden(true);
+}
+
+
+ECSubcircuit::~ECSubcircuit()
+{
+}
+
+
+void ECSubcircuit::removeItem()
+{
+ emit subcircuitDeleted();
+ Component::removeItem();
+}
+
+
+void ECSubcircuit::setNumExtCon( unsigned numExtCon )
+{
+ m_conNames.resize(numExtCon);
+
+ // Remove old pins
+ const NodeMap::iterator nodeMapEnd = m_nodeMap.end();
+ for ( NodeMap::iterator it = m_nodeMap.begin(); it != nodeMapEnd; ++it )
+ {
+ p_icnDocument->appendDeleteList( p_icnDocument->nodeWithID(it.data().id) );
+ }
+ p_icnDocument->flushDeleteList();
+ m_nodeMap.clear();
+
+ QStringList pins;
+ for ( unsigned i=0; i<numExtCon; ++i )
+ {
+ pins += QString::number(i);
+ }
+
+ initDIPSymbol( pins, 80 );
+
+ // We don't want the text that the dip symbol gave us as we initialize it later...
+ for ( unsigned i = 0; i < numExtCon; ++i )
+ removeDisplayText( QString::number(i) );
+
+ initDIP(pins);
+}
+
+
+void ECSubcircuit::dataChanged()
+{
+ int subcircuitId = dataInt("id");
+ if ( subcircuitId == -1 ) {
+ return;
+ }
+ emit subcircuitDeleted();
+ Subcircuits::initECSubcircuit( subcircuitId, this );
+}
+
+
+void ECSubcircuit::setExtConName( unsigned numId, const QString & name )
+{
+ if ( numId > m_conNames.size() )
+ return;
+
+ m_conNames[numId] = name;
+}
+
+
+void ECSubcircuit::doneSCInit()
+{
+ QStringList pins;
+ for ( unsigned i = 0; i < m_conNames.size(); ++i )
+ pins << m_conNames[i];
+ initDIPSymbol( pins, 80 );
+}
+
+
+void ECSubcircuit::drawShape( QPainter &p )
+{
+ Component::drawShape(p);
+}
+
+
+#include "ecsubcircuit.moc"
+
+
+