summaryrefslogtreecommitdiffstats
path: root/src/electronics/components/ecsubcircuit.cpp
blob: a69e720604a2c6788d4837819e72edcb7380f64d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/***************************************************************************
 *   Copyright (C) 2005 by David Saxton                                    *
 *   [email protected]                                                    *
 *                                                                         *
 *   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"