Exemplo n.º 1
0
QWidget* ParametersDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem& option, const QModelIndex &index) const
{
	const ParametersModel* model = static_cast< const ParametersModel* >( index.model() );
	SoField* field = model->ModelItem( index )->GetField();
	
	if( field->getTypeId().isDerivedFrom( SoSFEnum::getClassTypeId() ) )
	{
		QComboBox* editor = new QComboBox( parent );
		SoSFEnum* enumField = static_cast< SoSFEnum* >( field );
		for( int i = 0; i < enumField->getNumEnums() ; ++i )
		{
			SbName enumName;
			enumField->getEnum( i , enumName );
			editor->addItem( enumName.getString() );
		}
		return editor;
	}
	else if( field->getTypeId().isDerivedFrom( SoMField::getClassTypeId() ) )
	{
		ContainerEditor* editor = new ContainerEditor( parent );
	     editor->setGeometry(option.rect);

	     connect( editor, SIGNAL( editingFinished( )  ), this, SLOT( CloseEditor() ));
		return editor;
	}

	else
	{
		QLineEdit* editor = new QLineEdit(parent);
		return editor;
	}
}
Exemplo n.º 2
0
void ParametersDelegate::setEditorData(QWidget *editor,
                                     const QModelIndex &index) const
{
	const ParametersModel* model = static_cast< const ParametersModel* >( index.model() );
	SoField* field = model->ModelItem( index )->GetField();
	
	if( field->getTypeId().isDerivedFrom( SoSFEnum::getClassTypeId() ) )
	{

		SoSFEnum* enumField = static_cast< SoSFEnum* >( field );
		int selectedIndex = enumField->getValue();
		
		QComboBox* combo = static_cast<QComboBox *>(editor);
		combo->setCurrentIndex( selectedIndex );

	}
	else if( field->getTypeId().isDerivedFrom( SoMField::getClassTypeId() ) )
	{
		QString value = index.model()->data(index, Qt::DisplayRole).toString();
		ContainerEditor* containerEdit = static_cast< ContainerEditor *>(editor);

		containerEdit->SetData( value );

	}

	else
	{
		QString value = index.model()->data(index, Qt::DisplayRole).toString();
			
		QLineEdit  *textEdit = static_cast<QLineEdit *>(editor);
		textEdit->setText(value);
	}

}
Exemplo n.º 3
0
void
SoUnknownNode::createFromIsA(SoMFString *isA)
//
////////////////////////////////////////////////////////////////////////
{
    for (int i = 0; i < isA->getNum(); i++) {
	SoType t = SoType::fromName((*isA)[i]);

	if (t.canCreateInstance() &&
	    t.isDerivedFrom(SoNode::getClassTypeId())) {

	    SoNode *alternateRep = (SoNode *)t.createInstance();
	    alternateRep->ref();
#ifdef DEBUG
	    if (alternateRep == NULL) {
		SoDebugError::post("SoUnknownNode::createFromIsA",
				   "SoType.createInstance returned "
				   "NULL (type %s)",
				   t.getName().getString());
		return;
	    }
#endif
	    // Copy over all fields that are shared:
	    int num = instanceFieldData->getNumFields();
	    for (int j=0; j<num; j++) {
		const SbName &fieldName = instanceFieldData->getFieldName(j);
		SoField *f = instanceFieldData->getField(this, j);
		// Don't copy over fields with default values:
		if (f->isDefault()) continue;
		
		SoField *nf = alternateRep->getField(fieldName);
		if (nf != NULL && nf->getTypeId() == f->getTypeId()) {
		    nf->copyFrom(*f);
		    if (f->isConnectedFromField()) {
			SoField *cf;
			f->getConnectedField(cf);
			nf->connectFrom(cf);
		    } else if (f->isConnectedFromEngine()) {
			SoEngineOutput *eo;
			f->getConnectedEngine(eo);
			nf->connectFrom(eo);
		    }
		}
	    }
	    // And if alternateRep is a group, copy over hidden
	    // children:
	    if (alternateRep->isOfType(SoGroup::getClassTypeId())) {
		SoGroup *g = (SoGroup *)alternateRep;
		for (int kid = 0; kid < hiddenChildren.getLength();
		     kid++) {
		    g->addChild(hiddenChildren[kid]);
		}
	    }
	    addChild(alternateRep);
	    return;
	}
    }
}
Exemplo n.º 4
0
void
SoUnknownEngine::copyContents(const SoFieldContainer *fromFC,
			      SbBool copyConnections)
//
////////////////////////////////////////////////////////////////////////
{
    // Make sure the copy has the correct class name
    const SoUnknownEngine *fromUnk = (const SoUnknownEngine *) fromFC;
    setClassName(fromUnk->className);

    // For each input in the original engine, create a new input and add
    // it to the new engine

    // NOTE: We can't use SoEngine::copyContents() to copy the field
    // data, since that uses SoFieldData::overlay(), which assumes the
    // fields have the same offsets in both engines. Instead, we just
    // copy the field values ourselves.

    const SoFieldData *fromData = fromUnk->getFieldData();
    SoFieldData  *toData	= (SoFieldData *) getFieldData();
    int i;
    for (i = 0; i < fromData->getNumFields(); i++) {

	SoField      *fromField	= fromData->getField(fromUnk, i);
        const SbName fieldName	= fromData->getFieldName(i);
        SoType       fieldType	= fromField->getTypeId();
        SoField      *toField	= (SoField *) (fieldType.createInstance());

        toField->enableNotify(FALSE);
        toField->setContainer(this);
        toField->setDefault(TRUE);
        toField->enableNotify(TRUE);

        toData->addField(this, fieldName.getString(), toField);

	toField->setContainer(this);
	toField->copyFrom(*fromField);
	toField->setIgnored(fromField->isIgnored());
	toField->setDefault(fromField->isDefault());
	toField->fixCopy(copyConnections);
	if (fromField->isConnected() && copyConnections)
	    toField->copyConnection(fromField);
    }

    // Copy the outputs
    SoEngineOutputData *toOutData = (SoEngineOutputData *) getOutputData();

    SoEngineOutputList outList;
    fromUnk->getOutputs(outList);

    for(i = 0; i < outList.getLength(); i++) {
        SoEngineOutput *newOut = new SoEngineOutput;
        const SoType outType = outList[i]->getConnectionType();
	SbName outName;
        getOutputName( outList[i], outName );
	toOutData->addOutput(this, outName.getString(), newOut, outType);
	newOut->setContainer(this);
    }
}
Exemplo n.º 5
0
void
SoVRMLShape::notify(SoNotList * list)
{
  SoField * f = list->getLastField();
  if (f && f->getTypeId() == SoSFNode::getClassTypeId()) {
    PRIVATE(this)->childlistvalid = FALSE;
  }
  inherited::notify(list);
}
Exemplo n.º 6
0
int
main(void)
{
  SoDB::init();
  SoNodeKit::init();
  SoInteraction::init();

  SoTypeList tl;
  const unsigned int n = SoType::getAllDerivedFrom(SoNode::getClassTypeId(), tl);
  for (unsigned int i=0; i < n; i++) {
    (void)fprintf(stdout, "%s", tl[i].getName().getString());

    SoFieldContainer * fc = (SoFieldContainer *)
      (tl[i].canCreateInstance() ? tl[i].createInstance() : NULL);

    if (fc == NULL) {
      (void)fprintf(stdout, "  (abstract)\n");
      continue;
    }

    (void)fprintf(stdout, "\n");

    SoFieldList fl;
    const unsigned int nrf = fc->getAllFields(fl);
    for (unsigned int j=0; j < nrf; j++) {
      SoField * f = fl[j];
      SoType ftype = f->getTypeId();
      SbName fname;
      f->getContainer()->getFieldName(f, fname);
      (void)fprintf(stdout, "  %s (%s)\n",
                    fname.getString(),
                    ftype.getName().getString());

      if (ftype.isDerivedFrom(SoSFEnum::getClassTypeId())) {
        list_enums((SoSFEnum *)f);
      }
      else if (ftype.isDerivedFrom(SoMFEnum::getClassTypeId())) {
        list_enums((SoMFEnum *)f);
      }
    }
  }

  return 0;
}
Exemplo n.º 7
0
void
SoUnknownNode::copyContents(const SoFieldContainer *fromFC,
			    SbBool copyConnections)
//
////////////////////////////////////////////////////////////////////////
{
    // Make sure the copy has the correct class name
    const SoUnknownNode *fromUnk = (const SoUnknownNode *) fromFC;
    setClassName(fromUnk->className);

    // For each field in the original node, create a new field and add
    // it to the new node

    // NOTE: We can't use SoNode::copyContents() to copy the field
    // data, since that uses SoFieldData::overlay(), which assumes the
    // fields have the same offsets in both nodes. Instead, we just
    // copy the field values ourselves.

    const SoFieldData *fromData = fromUnk->getFieldData();
    SoFieldData  *toData	= (SoFieldData *) getFieldData();

    int i;
    for (i = 0; i < fromData->getNumFields(); i++) {

	SoField      *fromField	= fromData->getField(fromUnk, i);
        const SbName fieldName	= fromData->getFieldName(i);
        SoType       fieldType	= fromField->getTypeId();
        SoField      *toField	= (SoField *) (fieldType.createInstance());

        toField->enableNotify(FALSE);
        toField->setContainer(this);
        toField->setDefault(TRUE);
        toField->enableNotify(TRUE);

        toData->addField(this, fieldName.getString(), toField);

	toField->setContainer(this);
	toField->copyFrom(*fromField);
	toField->setIgnored(fromField->isIgnored());
	toField->setDefault(fromField->isDefault());
	toField->fixCopy(copyConnections);
	if (fromField->isConnected() && copyConnections)
	    toField->copyConnection(fromField);
    }

    // Copy the kids
    for (i = 0; i < fromUnk->hiddenChildren.getLength(); i++) {

	// If this node is being copied, it must be "inside" (see
	// SoNode::copy() for details.) Therefore, all of its children
	// must be inside, as well, since our addToCopyDict() takes
	// care of that.
	SoNode *fromKid = fromUnk->getChild(i);
	SoNode *kidCopy = (SoNode *) findCopy(fromKid, copyConnections);

#ifdef DEBUG
	if (kidCopy == NULL)
	    SoDebugError::post("(internal) SoUnknownNode::copyContents",
			       "Child %d has not been copied yet", i);
#endif /* DEBUG */

	hiddenChildren.append(kidCopy);
    }

    // No need to copy the override flag, since this flag will have no
    // effect on an unknown node, and it is not read from or written
    // to files.
}
Exemplo n.º 8
0
SbBool SoXipSFData::isSame(const SoField &f) const
{
    return (getTypeId() == f.getTypeId() &&
	    (*this) == (const SoXipSFData &) f);
}