Exemplo n.º 1
0
void qf_cmp1::dump (unsigned n1, unsigned n2,
		    Q3TextStream& com, Q3TextStream& wir) {

  // type of component
  if (name == "CAP")
    com << "<C C1";
  else if (name == "IND")
    com << "<L L1";
  else if (name == "RES")
    com << "<R R1";

  // single component to ground
  if (n2 == 0) {
    // wire
    wir << "<" << x << " " << y-30 << " " << x << " " << y-80
	<< " \"\" 0 0 0>\n";
    // position
    com << " 1 " << x << " " << y;
    com << " 17 -26 0 1";
    // value of component
    com << " \"" << valstr (val) << unit;
    com << "\" 1>\n";
    // place ground symbol here
    com << "<GND * 1 " << x << " " << y+30 << " 0 0 0 0>\n";
  }
  // single component in series
  else {
    // wires
    wir << "<" << x << " " << y-80 << " " << x+40 << " " << y-80
	<< " \"\" 0 0 0>\n";
    wir << "<" << x+100 << " " << y-80 << " " << x+140 << " " << y-80
	<< " \"\" 0 0 0>\n";
    // position
    com << " 1 " << x+70 << " " << y-80;
    com << " -26 10 0 0";
    // value of commponent
    com << " \"" << valstr (val) << unit;
    com << "\" 1>\n";
    x += 140;
  }
}
Exemplo n.º 2
0
Arquivo: main.c Projeto: d5h/gah
static size_t
print_names(WINDOW *w, struct annot *an)
{
  if (an == top)
    return 0;
  else
    {
      size_t cursoff = offset + cursor;
      size_t paroff = print_names(w, an->parent);
      size_t off = paroff + an->reloff;
      size_t index = (cursoff - off) / an->len;
      if (an->parent != top)
	wprintw(w, ".");
      wprintw(w, "%s", an->name);
      if (an->repeats)
	wprintw(w, "[%zi]", index);
      if (an->has_param)
	wprintw(w, "(%s)", valstr(&an->param));
      return off + index * an->len;
    }
}
Exemplo n.º 3
0
void ofxRemoteUI::setValuesFromString( string values ){

	stringstream in(values);
	string name, value;
	vector<string>changedParam;

	while( !in.eof() ){
		getline( in, name, '=' );
		getline( in, value, '\n' );

		if( params.find( name ) != params.end() ){
			RemoteUIParam param = params[name];
			RemoteUIParam original = params[name];
			changedParam.push_back(name);
			stringstream valstr( UriDecode(value) );

			switch (param.type) {
				case REMOTEUI_PARAM_FLOAT: valstr >> param.floatVal; break;
				case REMOTEUI_PARAM_INT: valstr >> param.intVal; break;
				case REMOTEUI_PARAM_COLOR: {
					std::istringstream ss(UriDecode(value));
					std::string token;
					std::getline(ss, token, ' '); param.redVal = atoi(token.c_str());
					std::getline(ss, token, ' '); param.greenVal = atoi(token.c_str());
					std::getline(ss, token, ' '); param.blueVal = atoi(token.c_str());
					std::getline(ss, token, ' '); param.alphaVal = atoi(token.c_str());
				}
				case REMOTEUI_PARAM_ENUM: valstr >> param.intVal; break;
				case REMOTEUI_PARAM_BOOL: valstr >> param.boolVal; break;
				case REMOTEUI_PARAM_STRING: param.stringVal = valstr.str(); break;
				case REMOTEUI_PARAM_SPACER: break;
				default: break;
			}

			if ( !param.isEqualTo(original) ){ // if the udpdate changed the param, keep track of it
				params[name] = param;
				paramsChangedSinceLastCheck.insert(name);
			}
		}
	}
Exemplo n.º 4
0
void qf_lcmp::dump_all (Q3TextStream& out) {

  if (lst.size () == 0) {
    return;
  }

  int node = 1;
  QByteArray  buf1, buf2;
  Q3TextStream com (buf1, QIODevice::ReadWrite);
  Q3TextStream wir (buf2, QIODevice::ReadWrite);

  x = 0;
  y = 0;

  // schematic start
  out << "<Qucs Schematic " << PACKAGE_VERSION << ">\n";

  // input port and according ground symbol
  com << "<Pac P1 1 " << x << " " << y << " 18 -26 0 1 \"1\" 1 \""
      << r1 << " Ohm\" 1 \"0 dBm\" 0 \"1 GHz\" 0>\n";
  com << "<GND * 1 " << x << " " << y+30 << " 0 0 0 0>\n";
  wir << "<" << x << " " << y-30 << " " << x << " " << y-80
      << " \"\" 0 0 0>\n";
  wir << "<" << x << " " << y-80 << " " << x+110 << " " << y-80
      << " \"\" 0 0 0>\n";

  x += 110;
  for (list <qf_cmp*>::iterator i = lst. begin (); i != lst. end ();) 
    if ((node = dump_node (node, i, com, wir)) < 0) break;

  // output port and according ground symbol
  x += 110;
  wir << "<" << x << " " << y-30 << " " << x << " " << y-80
      << " \"\" 0 0 0>\n";
  wir << "<" << x-110 << " " << y-80 << " " << x << " " << y-80
      << " \"\" 0 0 0>\n";
  com << "<Pac P2 1 "<< x << " " << y << " 18 -26 0 1 \"2\" 1 \""
      << r2 << " Ohm\" 1 \"0 dBm\" 0 \"1 GHz\" 0>\n"
      << "<GND * 1 " << x << " " << y+30 << " 0 0 0 0>\n";

  x = 0;

  // S-parameter simulation box and equation
  com << "<.SP SP1 1 " << x << " " << y-280 << " 0 50 0 0 \"log\" 1 \""
      << valstr(fc/2/M_PI/10) << "Hz\" 1 \"" << valstr(fc/2/M_PI*10)
      << "Hz\" 1 \"200\" 1 \"no\" 0 \"1\" 0 \"2\" 0>\n";
  com << "<Eqn Eqn1 1 " << x+200 << " " << y-270
      << " -28 15 0 0 \"dBS21=dB(S[2,1])\" 1 "
      << "\"dBS11=dB(S[1,1])\" 1 \"yes\" 0>\n";

  // components
  out << "<Components>\n";
  out << QString(buf1);
  out << "</Components>\n";
  // wires
  out << "<Wires>\n";
  out << QString(buf2);
  out << "</Wires>\n";
  // paintings
  out << "<Paintings>\n";
  out << "<Text " << x+310 << " " << y-280 << " 12 #000000 0 \""
      << tx << "\\n"
      << valstr(fc/2/M_PI) << "Hz cutoff/center frequency\\n"
      << "impedance matching Z_{IN}=" << valstr(r1) << "\\Omega, Z_{OUT}="
      << valstr(r2) << "\\Omega\">\n";
  out << "</Paintings>\n";
}
Exemplo n.º 5
0
void qf_cmplc::dump (unsigned n1, unsigned n2,
		     Q3TextStream& com, Q3TextStream& wir) {

  if (name == "PLC") {
    // parallel L and C to ground
    if (n2 == 0) {
      // wire
      wir << "<" << x << " " << y-30 << " " << x << " " << y-80
	  << " \"\" 0 0 0>\n";
      // inductor
      com << "<L L1";
      // position
      com << " 1 " << x << " " << y;
      com << " 17 -26 0 1";
      // value of component
      com << " \"" << valstr (vL) << "H";
      com << "\" 1>\n";
      // place ground symbol here
      com << "<GND * 1 " << x << " " << y+30 << " 0 0 0 0>\n";

      // connecting above wire
      wir << "<" << x << " " << y-80 << " " << x+110 << " " << y-80
	  << " \"\" 0 0 0>\n";

      x += 110;

      // wire
      wir << "<" << x << " " << y-30 << " " << x << " " << y-80
	  << " \"\" 0 0 0>\n";
      // capacitor
      com << "<C C1";
      // position
      com << " 1 " << x << " " << y;
      com << " 17 -26 0 1";
      // value of component
      com << " \"" << valstr (vC) << "F";
      com << "\" 1>\n";
      // place ground symbol here
      com << "<GND * 1 " << x << " " << y+30 << " 0 0 0 0>\n";
    }
    // parallel L and C in series
    else {
      // wires
      wir << "<" << x << " " << y-80 << " " << x+40 << " " << y-80
	  << " \"\" 0 0 0>\n";
      wir << "<" << x+100 << " " << y-80 << " " << x+140 << " " << y-80
	  << " \"\" 0 0 0>\n";
      // inductor
      com << "<L L1";
      // position
      com << " 1 " << x+70 << " " << y-80;
      com << " -26 10 0 0";
      // value of commponent
      com << " \"" << valstr (vL) << "H";
      com << "\" 1>\n";

      // wires
      wir << "<" << x+40 << " " << y-80 << " " << x+40 << " " << y-120
	  << " \"\" 0 0 0>\n";
      wir << "<" << x+100 << " " << y-80 << " " << x+100 << " " << y-120
	  << " \"\" 0 0 0>\n";
      // capacitor
      com << "<C C1";
      // position
      com << " 1 " << x+70 << " " << y-120;
      com << " -26 -48 0 0";
      // value of commponent
      com << " \"" << valstr (vC) << "F";
      com << "\" 1>\n";

      x += 140;
    }
  }
  else if (name == "SLC") {
    // series L and C to ground
    if (n2 == 0) {
      // wire
      wir << "<" << x << " " << y-30 << " " << x << " " << y-80
	  << " \"\" 0 0 0>\n";
      // inductor
      com << "<L L1";
      // position
      com << " 1 " << x << " " << y;
      com << " 17 -26 0 1";
      // value of component
      com << " \"" << valstr (vL) << "H";
      com << "\" 1>\n";

      // capacitor
      com << "<C C1";
      // position
      com << " 1 " << x << " " << y+60;
      com << " 17 -26 0 1";
      // value of component
      com << " \"" << valstr (vC) << "F";
      com << "\" 1>\n";
      // place ground symbol here
      com << "<GND * 1 " << x << " " << y+90 << " 0 0 0 0>\n";
    }
    // series L and C in series
    else {
      // wires
      wir << "<" << x << " " << y-80 << " " << x+40 << " " << y-80
	  << " \"\" 0 0 0>\n";
      wir << "<" << x+100 << " " << y-80 << " " << x+120 << " " << y-80
	  << " \"\" 0 0 0>\n";
      wir << "<" << x+180 << " " << y-80 << " " << x+220 << " " << y-80
	  << " \"\" 0 0 0>\n";
      // inductor
      com << "<L L1";
      // position
      com << " 1 " << x+70 << " " << y-80;
      com << " -26 10 0 0";
      // value of commponent
      com << " \"" << valstr (vL) << "H";
      com << "\" 1>\n";

      // capacitor
      com << "<C C1";
      // position
      com << " 1 " << x+150 << " " << y-80;
      com << " -26 10 0 0";
      // value of commponent
      com << " \"" << valstr (vC) << "F";
      com << "\" 1>\n";

      x += 220;
    }
  }
}
Exemplo n.º 6
0
Config* PyGLPSParse2Config(PyObject *, PyObject *args, PyObject *kws)
{
    PyObject *conf = NULL, *extra_defs = Py_None;
    const char *path = NULL;
    const char *pnames[] = {"config", "path", "extra", NULL};
    if(!PyArg_ParseTupleAndKeywords(args, kws, "O|zO", (char**)pnames, &conf, &path, &extra_defs))
        return NULL;

    GLPSParser parser;

    if(extra_defs==Py_None) {
        // no-op
    } else if(PyDict_Check(extra_defs)) {
        PyObject *key, *value;
        Py_ssize_t pos = 0;

        while(PyDict_Next(extra_defs, &pos, &key, &value)) {
            PyRef<> keyx(key, borrow());
            PyCString keystr(keyx);

            Config::value_t curval;

            if(PyNumber_Check(value)) {
                PyRef<> pyf(PyNumber_Float(value));
                curval = PyFloat_AsDouble(pyf.py());

            } else if(PyString_Check(value)) {
                PyRef<> valuex(value, borrow());
                PyCString valstr(valuex);

                curval = valstr.c_str();

            } else {
                PyErr_SetString(PyExc_ValueError, "extra {} can contain only numbers or strings");
                return NULL;
            }

            parser.setVar(keystr.c_str(), curval);
        }
    } else {
        PyErr_SetString(PyExc_ValueError, "'extra' must be a dict");
        return NULL;
    }

    PyGetBuf buf;
    std::auto_ptr<Config> C;

    PyRef<> listref;

    if(PyObject_HasAttrString(conf, "read")) { // file-like
        PyCString pyname;

        if(!path && PyObject_HasAttrString(conf, "name")) {
            path = pyname.c_str(pydirname(PyObject_GetAttrString(conf, "name")));
        }

        PyRef<> pybytes(PyObject_CallMethod(conf, "read", ""));
        if(!buf.get(pybytes.py())) {
            PyErr_SetString(PyExc_TypeError, "read() must return a buffer");
            return NULL;
        }
        C.reset(parser.parse_byte((const char*)buf.data(), buf.size(), path));

    } else if(buf.get(conf)) {
        C.reset(parser.parse_byte((const char*)buf.data(), buf.size(), path));

#if PY_MAJOR_VERSION >= 3
    } else if(PyUnicode_Check(conf)) { // py3 str (aka unicode) doesn't implement buffer iface
        PyCString buf;
        const char *cbuf = buf.c_str(conf);

        C.reset(parser.parse_byte(cbuf, strlen(cbuf), path));
#endif

    } else {
        if(PyDict_Check(conf)) {
            listref.reset(PyMapping_Items(conf));
            conf = listref.py();
        }
        if(PyList_Check(conf)) {
            C.reset(list2conf(conf));

        } else {
            throw std::invalid_argument("'config' must be dict, list of tuples, or byte buffer");
        }
    }

    return C.release();
}