#include "JComplexObj.h" #include "JLinkObj.h" #include "JPObject.h" #include "JInteger.h" #include "JDouble.h" #include "JMessageBox.h" #include "JStringProperty.h" #include "JIntegerProperty.h" #include "JIntegerListProperty.h" char* theJComplexObj = JComplexObj().Register(); #define FACTOR 8 #define FACTOR2 16 class JPort : public JObject { public: virtual const char* className() const; virtual JObject* clone() const; JPort(); JPort(JString name); JString name; int valueCounter; int typeCounter; }; #define PORT(x) ((JPort*)x) const char* JPort::className() const { return "JPort";} JObject* JPort::clone() const { return new JPort(*this);} JPort::JPort() { valueCounter = typeCounter = 0;} JPort::JPort(JString _name) { name = _name; valueCounter = typeCounter = 0;} void JComplexObj::writeContent(JOutputStream& os) { JAddObj::writeContent(os); putString(os, "name", name); putInteger(os, "numOfInput", numOfInput); putInteger(os, "numOfLeftInput", numOfLeftInput); putInteger(os, "numOfOutput", numOfOutput); putInteger(os, "numOfRightOutput", numOfRightOutput); putInteger(os, "internalMode", internalMode); igm = ogm = numOfInput+numOfOutput; JString prefix; for (int i=0; iname); } } void JComplexObj::readContent(JDictionary& dict) { JAddObj::readContent(dict); name = getString(dict, "name"); numOfInput = getInteger(dict, "numOfInput"); numOfLeftInput = getInteger(dict, "numOfLeftInput"); numOfOutput = getInteger(dict, "numOfOutput"); numOfRightOutput = getInteger(dict, "numOfRightOutput"); internalMode = getInteger(dict, "internalMode"); igm = ogm = numOfInput+numOfOutput; JString prefix; port.Release(); for (int i=0; ivalueCounter; JLinkObj* prev = (JLinkObj*)inputSet(n).first(); if (prev) { if (!valueCounter++) prev->access(data); valueCounter--; } } int JComplexObj::inputType(int n) { int type = JDataType::last; int &typeCounter = PORT(port[n])->typeCounter; JLinkObj* link = (JLinkObj*)inputSet(n).first(); if (link) { if (!typeCounter++) type = link->from->outputType(link->fn); typeCounter--; } if (type == JDataType::last) { link = (JLinkObj*)outputSet(n).first(); if (link) { if (!typeCounter++) type = link->to->inputType(link->tn); typeCounter--; } } return type; } int JComplexObj::outputType(int n) { return inputType(n);} JString JComplexObj::inputTag(int n) { if (n < numOfInput) return PORT(port[n])->name; if (n < numOfInput+numOfOutput) return PORT(port[n])->name+"(inner)"; return "None"; } JString JComplexObj::outputTag(int n) { if (n < numOfInput) return PORT(port[n])->name+"(inner)"; if (n < numOfInput+numOfOutput) return PORT(port[n])->name; return "None"; } boolean JComplexObj::inputAllowed(int n) { return !inputSet(n).last();} JFRect JComplexObj::inputArea(int n) { JFRect rect; int factor = (internalMode) ? FACTOR2 : FACTOR; if (n < numOfLeftInput) { rect = leftArea(n, 0, numOfLeftInput, 0.25, 0.5, factor); } else if (n < numOfInput) { rect = topArea(n, numOfLeftInput, numOfInput-numOfLeftInput, 0.25, 0.5, factor); } else if (n < numOfInput+numOfRightOutput) { rect = rightArea(n, numOfInput, numOfRightOutput, 0.25, 0.5, factor); rect.x -= min(width, height)/factor; } else { rect = bottomArea(n, numOfInput+numOfRightOutput, numOfOutput-numOfRightOutput, 0.25, 0.5, factor); rect.y -= min(width, height)/factor; } return rect; } JFRect JComplexObj::outputArea(int n) { JFRect rect; int factor = (internalMode) ? FACTOR2 : FACTOR; if (n < numOfLeftInput) { rect = leftArea(n, 0, numOfLeftInput, 0.25, 0.5, factor); rect.x += min(width, height)/factor; } else if (n < numOfInput) { rect = topArea(n, numOfLeftInput, numOfInput-numOfLeftInput, 0.25, 0.5, factor); rect.y += min(width, height)/factor; } else if (n < numOfInput+numOfRightOutput) { rect = rightArea(n, numOfInput, numOfRightOutput, 0.25, 0.5, factor); } else { rect = bottomArea(n, numOfInput+numOfRightOutput, numOfOutput-numOfRightOutput, 0.25, 0.5, factor); } return rect; } int JComplexObj::inputAreaNo(JFPoint fpt) { if (internalMode) return JAddObj::inputAreaNo(fpt); for (int i=0; iname)); } } return properties; } boolean JComplexObj::checkEmpty() { int i; for (i=0; ivalue; return true; } else if (prop.getName() == JString("internalMode")) { internalMode = ((JIntegerListProperty*)&prop)->value; repaintView(*this, REGION_MODE); return true; } else if (prop.getName() == JString("numOfLeftInput")) { if (!checkEmpty()) { JMessageBox::create("Disconnect all links before change number of ports !", JMessageBox::BTN_OK); return true; } int delta, oldN = numOfLeftInput; numOfLeftInput = ((JIntegerProperty*)&prop)->value; delta = numOfLeftInput-oldN; if (!delta) return true; if (delta < 0) port.del(numOfLeftInput, -delta); else port.insert(JPort("None"), oldN, delta); numOfInput += delta; igm = ogm = numOfInput+numOfOutput; return true; } else if (prop.getName() == JString("numOfTopInput")) { if (!checkEmpty()) { JMessageBox::create("Disconnect all links before change number of ports !", JMessageBox::BTN_OK); return true; } int delta, oldN = numOfInput; numOfInput = numOfLeftInput+((JIntegerProperty*)&prop)->value; delta = numOfInput-oldN; if (!delta) return true; if (delta < 0) port.del(numOfInput, -delta); else port.insert(JPort("None"), oldN, delta); igm = ogm = numOfInput+numOfOutput; return true; } else if (prop.getName() == JString("numOfRightOutput")) { if (!checkEmpty()) { JMessageBox::create("Disconnect all links before change number of ports !", JMessageBox::BTN_OK); return true; } int delta, oldN = numOfRightOutput; numOfRightOutput = ((JIntegerProperty*)&prop)->value; delta = numOfRightOutput-oldN; if (!delta) return true; if (delta < 0) port.del(numOfRightOutput, -delta); else port.insert(JPort("None"), oldN, delta); numOfOutput += delta; igm = ogm = numOfInput+numOfOutput; return true; } else if (prop.getName() == JString("numOfBottomOutput")) { if (!checkEmpty()) { JMessageBox::create("Disconnect all links before change number of ports !", JMessageBox::BTN_OK); return true; } int delta, oldN = numOfOutput; numOfOutput = numOfRightOutput+((JIntegerProperty*)&prop)->value; delta = numOfOutput-oldN; if (!delta) return true; if (delta < 0) port.del(numOfOutput, -delta); else port.insert(JPort("None"), oldN, delta); igm = ogm = numOfInput+numOfOutput; return true; } JString prefix; for (int i=0; iname = ((JStringProperty*)&prop)->value; return true; } } return false; } DllImport void DoAddModuleLinks(const JObject* obj, void** arg); boolean DoDelLinks(const JObject* obj, void** arg) { if (obj == (JObject*)arg[2]) return false; ((JModuleObj*)obj)->addLinks( *(JViewSet*)arg[0], *(JHashTable*)arg[1]); return false; } void JComplexObj::addLinks(JViewSet& set, JHashTable& hash) { if (internalMode) { JAddObj::addLinks(set, hash); return; } int i; void* arg[] = {&set, &hash}; for (i=0; ilastNodeThat(DoDelLinks, arg); } } JString JComplexObj::getPrefix(int i) { if (i < numOfLeftInput) return JString("left-")+JInteger::toJString(i); else if (i < numOfInput) return JString("top-")+JInteger::toJString(i-numOfLeftInput); else if (i < numOfInput+numOfRightOutput) return JString("right-")+JInteger::toJString(i-numOfInput); return JString("bottom-")+JInteger::toJString(i-numOfInput-numOfRightOutput); }