예제 #1
0
void
SoVRMLAudioClipP::loadUrl()
{
#ifdef HAVE_THREADS
  SbThreadAutoLock autoLock(&this->syncmutex);
#endif
  this->unloadUrl();

  for (int i=0; i<PUBLIC(this)->url.getNum(); i++) {
    const char * str = PUBLIC(this)->url[i].getString();
    if ( (str == NULL) || (strlen(str)==0) )
      continue; // ignore empty url

    SbString filename =
      SoInput::searchForFile(SbString(str), SoInput::getDirectories(),
                             SoVRMLAudioClip::getSubdirectories());

    if (filename.getLength() <= 0) {
      SoDebugError::postWarning("SoVRMLAudioClipP::loadUrl(index)",
                                "File not found: '%s'",
                                str);
      continue; // ignore invalid file
    }

    this->playlist.append(filename);
  }
}
예제 #2
0
SbString XipStrExpandEnv(const char *strIn)
{
	std::string str(strIn);
	int pos = 0;
	int start = 0;
	int end = 0;

	while ((start = static_cast<int>(str.find("$(", pos))) >= 0)
	{
		end = str.find(")", start);
		if (end <= 0) break;

		std::string var = str.substr(start + 2, end - start - 2);
		const char *varValue = ::getenv(var.c_str());
		if (varValue)
		{
			str.erase(start, end - start + 1);
			str.insert(start, varValue);

			pos = start + strlen(varValue);
		}
		else pos = end;
	}

	return SbString(str.c_str());
}
예제 #3
0
/*!
  Creates an instance of a suitable SoForeignFileKit subtype.
  Returns NULL on failure or a kit with refcount of 1 on success.
*/
static SoForeignFileKit *create_foreignfilekit(const char *filename, SbBool exhaust)
{
  assert(SoForeignFileKitP::fileexts != NULL);

  const char * extptr = strrchr(filename, '.');
  if (extptr) {
    extptr++;
    SbName ext(SbString(extptr).lower());
    SoType handler = SoType::badType();
    if (SoForeignFileKitP::fileexts->get(ext.getString(), handler)) {
      SoForeignFileKit * foreignfile = (SoForeignFileKit *)handler.createInstance();
      foreignfile->ref();
      if (foreignfile->canReadFile(filename)) {
        return foreignfile;
      }
      else {
        foreignfile->unref();
      }
    }
    else {
      // We try to synthesize a classname from the extension (e.g. SoFBXFileKit),
      // and load it using the SoType autoloader feature.
      SbString filekitname;
      filekitname.sprintf("So%sFileKit", SbString(ext.getString()).upper().getString());
      SoType filekittype = SoType::fromName(SbName(filekitname));
      if (!filekittype.isBad()) return create_foreignfilekit(filename, exhaust);

      // FIXME: Some filekits supports more than one file format/extension (e.g. FBX).
      // We need a way of mapping extensions to library, or a way of loading
      // each external kit and testing for support.
      // FIXME: Temporary hack: Load SoFBXFileKit
      filekitname = "SoFBXFileKit";
      filekittype = SoType::fromName(SbName(filekitname));
      if (!filekittype.isBad()) return create_foreignfilekit(filename, exhaust);
    }
  }
  if (exhaust) {
    // FIXME: Implement
    // SoForeignFileKitP::fileexts->apply()
  }
  return NULL;
}
예제 #4
0
SbString SoXipData::getProperty(const SbString key) const
{
	if (mProperties)
	{
		SbXipDataPropertyMap::const_iterator it;
		it = mProperties->find(key);
		if (it != mProperties->end())
			return it->second;
	}

	return SbString("");
}
예제 #5
0
//replaces all occurances of "searchChar" in "str" with "replChar"
SbString XipReplaceChar(const char * str, const char & searchChar, const char & replChar)
{
    std::string tmpStr(str);
    for (unsigned int i=0; i<tmpStr.size(); i++)
    {
        if ( tmpStr.at(i) == searchChar )
        {
            tmpStr[i] = replChar;
        }
    }
    return SbString(tmpStr.c_str());
}
void
SoXipImageOverlayManager::addOverlays()
{
	const SoNode** nodes = overlays.getValues(0);

	for( int i = 0; i < overlays.getNum(); ++ i )
	{
		const SoXipShapeList* shapeList = (const SoXipShapeList *) nodes[i];

		if( !shapeList->isOfType( SoXipShapeList::getClassTypeId() ) )
		{
			SoDebugError::post( __FILE__, "Child not supported" );
			return ;
		}

		int sliceIndex;
		if( sscanf( shapeList->label.getValue().getString(), "%d", &sliceIndex ) != 1 )
		{
			SoDebugError::post( __FILE__, "Invalid label found '%s'", shapeList->label.getValue().getString() );
			return ;
		}

		SoXipShapeList* sliceShapeList = mSliceMap[ sliceIndex ];
		if( !sliceShapeList )
		{
			sliceShapeList = new SoXipShapeList;
			sliceShapeList->label.setValue( SbString( sliceIndex ) );

			mShapeSwitch->addChild( sliceShapeList );

			mSliceMap[ sliceIndex ] = sliceShapeList;
		}

		int numShapes = shapeList->getNumChildren();
		for( int i = 0; i < numShapes; ++ i )
		{
			// Copy to string to force removing of the connections
			SoNode* copyNode = shapeList->getChild (i)->copy();
			copyNode->ref();
			SbString str = XipOverlayUtils::saveNodeToString( copyNode );
			copyNode->unref();

			// Reload copy node from this string
			SoNode* readNode = XipOverlayUtils::loadNodeFromString( str.getString(), str.getLength() );
			((SoXipShape *) readNode)->updateGeometries();
			sliceShapeList->addChild( readNode );
		}
	}
}
예제 #7
0
void HxGLSLVertexView::setRenderMode(DrawStyles mode)
{
    const SbString shaderPath = SbString(HxResource::getRootDir()) + "/share/shaders/hxglslvertexview/";
    
    m_p_geometryshader->parameter.removeAllShaderParameters();

    if (mode == POINTS)
    {
        m_p_shaderProgram->geometryOutputType = SoShaderProgram::POINTS_OUTPUT;
        m_p_shaderProgram->maxGeometryOutputVertices = 1;
    }
    else
    {
        m_p_shaderProgram->geometryOutputType = SoShaderProgram::TRIANGLE_STRIP_OUTPUT;
        m_p_shaderProgram->maxGeometryOutputVertices = 4;

        m_p_geometryshader->parameter.addShaderParameter(m_p_sphereSizeParameter);
    }

    if (mode == HAZE)
        m_p_material->transparency =  1.0f;
    else
        m_p_material->transparency.deleteValues(0);

    switch(mode)
    {
    case POINTS:
        m_p_vertexShader->sourceProgram   = shaderPath + "points-vert.glsl";
        m_p_geometryshader->sourceProgram = shaderPath + "points-geom.glsl";
        m_p_fragmentshader->sourceProgram = shaderPath + "points-frag.glsl";
        break;
    case PLATES:
        m_p_vertexShader->sourceProgram   = shaderPath + "quad-vert.glsl";
        m_p_geometryshader->sourceProgram = shaderPath + "quad-geom.glsl";
        m_p_fragmentshader->sourceProgram = shaderPath + "plates-frag.glsl";
        break;
    case HAZE:
        m_p_vertexShader->sourceProgram   = shaderPath + "quad-vert.glsl";
        m_p_geometryshader->sourceProgram = shaderPath + "quad-geom.glsl";
        m_p_fragmentshader->sourceProgram = shaderPath + "hazes-frag.glsl";
        break;
    case SPHERES:
        m_p_vertexShader->sourceProgram   = shaderPath + "quad-vert.glsl";
        m_p_geometryshader->sourceProgram = shaderPath + "quad-geom.glsl";
        m_p_fragmentshader->sourceProgram = shaderPath + "spheres-frag.glsl";
        break;
    }
}
예제 #8
0
SoXipCheckGLStacks::SoXipCheckGLStacks(void)
{
    SO_NODE_CONSTRUCTOR(SoXipCheckGLStacks);

    SO_NODE_ADD_FIELD(checkState, (TRUE));
    SO_NODE_ADD_FIELD(label, (SbString("")));

    mProjectionStackDepth = 1;
    mModelviewStackDepth = 1;
    mColorStackDepth = 1;
    mTextureStackDepth = 1;
    mAttribStackDepth = 1;

    mMaxProjectionStackDepth = -1;
    mMaxModelviewStackDepth = -1;
    mMaxColorStackDepth = -1;
    mMaxTextureStackDepth = -1;
    mMaxAttribStackDepth = -1;
}
예제 #9
0
SbString 
formatLength( float length )
{
	char tmp[30];

	if (length > 100.f)
	{
		sprintf(tmp, "%.3f cm", length / 10.f);
	}
	else if (length < 0.010f)
	{
		sprintf(tmp, "%.3f µm", length * 1000.f);
	}
	else
	{
		sprintf(tmp, "%.3f mm", length);
	}

	return SbString(tmp);
}
void
SoXipImageOverlayManager::updateOverlays( SoAction* action )
{
	if( imageChanged( action ) )
	{
		this->saveOverlays();

		if( mImageData )
		{
			mImageData->unref();		
			mImageData = 0;
		}

		SoXipDataImage* eltData = SoXipDataImageElement::get( action->getState() );

		// Reset the current slice to force the update
		mCurrentSlice = -1;

		if( eltData )
		{
			// Get reference image
			SoXipDataImage* refData = 0;
			SoXipDataImage* eltData = SoXipDataImageElement::get( action->getState() );
	
			while( (refData = (SoXipDataImage *) eltData->getRefByType( SoXipDataImage::getClassTypeId() )) )
				eltData = refData;

			mImageData = eltData;
			mImageData->ref();

			// retrieve ROI overlay from Dicom
			this->loadOverlays();
		}
	}

	int sliceIndex = SoXipDataImageElement::getSliceIndex( action->getState() );
	if( sliceIndex != mCurrentSlice )
	{
		// When switching to a different slice, unselect all the shapes that were
		// previously selected.
		SoNodeList selection = XipOverlayUtils::getTopLevelShapes( mShapeSwitch, TRUE );	

		for( int i = 0; i < selection.getLength(); ++ i )
			((SoXipShape *) selection[i])->select( FALSE );

		mSelection.truncate(0);

		SoXipShapeList* sliceShapeList = mSliceMap[ sliceIndex ];
		if( sliceShapeList )
		{
			mShapeSwitch->whichChild.setValue( mShapeSwitch->findChild( sliceShapeList ) );
		}
		else
		{
			sliceShapeList = new SoXipShapeList;
			sliceShapeList->label.setValue( SbString( sliceIndex ) );
			
			mShapeSwitch->addChild( sliceShapeList );
			mShapeSwitch->whichChild.setValue( mShapeSwitch->getNumChildren() - 1 );

			mSliceMap[ sliceIndex ] = sliceShapeList;
		}

		mCurrentSlice = sliceIndex;
	}
}
예제 #11
0
void MFieldEditor::on_buttonBox_clicked(QAbstractButton * button)
{
	if (Ui.buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole)
	{
		QString S;
		SbString oldValue;

		//Buscamos el SoMField que estamos editando
		SoMField *field = current_mfield;

		//Leemos el tipo de este campo
		SoType tipo=field->getTypeId();
		const char*nombre_tipo = tipo.getName();  

		//Actualizamos el contenido del SoMField

		//Si es necesario, ampliamos el tamaño del SoMField
		field->setNum(Ui.table->rowCount()-1);

		//Miramos cuantas columnas tiene la tabla
		int numComp = Ui.table->columnCount();

		//Tratamiento de los campos SoMFString
		if (!strcmp(nombre_tipo, "MFString") )
		{
			//Convertimos el campo a SoMFString
			SoMFString *soMFString = (SoMFString *)field;

			//Recorremos las filas de la tabla
			for(int i=0;i<Ui.table->rowCount()-1;i++)
			{
				//Extraemos el contenido de las celdas
				S = Ui.table->item(i,0)->text();

				//Aplicamos el valor al campo
				soMFString->set1Value(i, SbString(qPrintable(S)));

			} // for(int i=0;i<Ui.table->rowCount()-1;i++)
		}
		else

			//Recorremos las filas de la tabla
			for(int i=0;i<Ui.table->rowCount()-1;i++)
			{
				//Sacamos una copia del field actual, por si hay errores
				field->get1(i, oldValue);
				//qDebug("old: %s\n", oldValue.getString());

				//Extraemos el contenido de la primera celda
				S = Ui.table->item(i,0)->text();

				//Concatenamos el resto de celdas de la fila
				for (int j=1; j < numComp; j++)
				{
					S.append(' ');
					S.append(Ui.table->item(i,j)->text());
				}

				//Leemos la cadena mediante el parser de openInventor
				//fprintf(stderr, "Introduciendo: %s\n", txt);
				if (!field->set1(i, qPrintable(S)))
				{
					//Si hubo un error en la lectura, restablecemos el valor anterior
					field->set1(i, oldValue.getString() );
					QMessageBox::warning( this, tr("Warning"), tr("Error on row:")+S.setNum(i));
					qDebug("Error leyendo campo en fila %d\n", i);
				}

			}//for

	}//if (Ui.buttonBox->buttonRole(button) == QDialogButtonBox::ApplyRole)
}