void
SoXipImageOverlayManager::updateSliceMap()
{
	// Removes all the previous entries
	mSliceMap.clear();

	SoSearchAction sa;
	sa.setInterest( SoSearchAction::ALL );
	sa.setType( SoXipShapeList::getClassTypeId() );
	sa.setSearchingAll( TRUE );
	sa.apply( mShapeSwitch );

	SoPathList paths = sa.getPaths();
	for( int i = 0; i < paths.getLength(); ++ i )
	{
		SbString label = ((SoXipShapeList *) paths[i]->getTail())->label.getValue().getString();

		int sliceIndex;
		if( sscanf( label.getString(), "%d", &sliceIndex ) != 1 )
		{
			SoDebugError::post( __FILE__, "Invalid label found '%s'", label.getString() );
			continue  ;
		}
		
		mSliceMap[ sliceIndex ] = (SoXipShapeList *) paths[i]->getTail();
	}
}
Ejemplo n.º 2
0
// add a name to the upgrader lookup dict.
static void
soupgrader_add_to_namedict(const SbString & name)
{
  assert(soupgrader_namedict);

  // Note: the SbString->SbName wrapping is necessary, or the const
  // char* will _not_ be valid upon the SbString going out of scope
  // (while SbName makes permanent const char* references).
  soupgrader_namedict->put(SbName(name.getString()).getString(), NULL);

  // Create lookup both with and without the "So" prefix. This is
  // necessary for the hash lookup in soupgrader_exists() to match
  // with both permutations.

  SbString tmp;
  if (name.compareSubString("So") == 0) {
    tmp = name.getSubString(2);
  }
  else {
    tmp = "So";
    tmp += name;
  }

  // Note: the SbString->SbName wrapping is necessary, see above
  // comment.
  soupgrader_namedict->put(SbName(tmp.getString()).getString(), NULL);
}
void ViewProviderVRMLObject::addResource(const SbString& url, std::list<std::string>& resources)
{
    SbString found = SoInput::searchForFile(url, SoInput::getDirectories(), SbStringList());
    Base::FileInfo fi(found.getString());
    if (fi.exists()) {
        // add the resource file if not yet listed
        if (std::find(resources.begin(), resources.end(), found.getString()) == resources.end()) {
            resources.push_back(found.getString());
        }
    }
}
Ejemplo n.º 4
0
void
SoHandleBoxDragger::updateArrows(void)
{
  int i;
  SbString str;
  SoSwitch *sw;

  if (this->constraintState >= CONSTRAINT_X) {
    int onval = -1;
    switch (this->constraintState) {
    case CONSTRAINT_X:
      onval = 3;
      break;
    case CONSTRAINT_Y:
      onval = 1;
      break;
    case CONSTRAINT_Z:
      onval = 5;
      break;
    }
    for (i = 1; i <= 6; i++) {
      str.sprintf("arrow%dSwitch", i);
      sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch);
      if (i == onval || i == onval + 1) {
        SoInteractionKit::setSwitchValue(sw, 0);
      }
      else {
        SoInteractionKit::setSwitchValue(sw, SO_SWITCH_NONE);
      }
    }
  }
  else if (this->whatkind == WHATKIND_TRANSLATOR) {
    int num = (this->whatnum-1) & ~1;
    for (i = 0; i < 6; i++) {
      str.sprintf("arrow%dSwitch", i+1);
      sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch);
      if (i == num || i == num+1) {
        SoInteractionKit::setSwitchValue(sw, SO_SWITCH_NONE);
      }
      else {
        SoInteractionKit::setSwitchValue(sw, 0);
      }
    }
  }
  else {
    for (i = 1; i <= 6; i++) {
      str.sprintf("arrow%dSwitch", i);
      sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch);
      SoInteractionKit::setSwitchValue(sw, SO_SWITCH_NONE);
    }
  }
}
Ejemplo n.º 5
0
SbBool 
writeImage( const char* file, unsigned int offset, SbXipImage& image )
{
#ifdef WIN32
    //assuming everything is done using the bad backslashes... so we convert all forward slashes to those
    const char * fileLocal = XipReplaceChar(file, '/', '\\').getString();
#else //UNIX
    //assuming the other way around since we need forward slashes now...
    const char * fileLocal = XipReplaceChar(file, '\\', '/').getString();
#endif //WIN32
    
	int r = 0;

	void* imageBufferPtr = image.refBufferPtr();
	if( imageBufferPtr )
	{
		SbString path = XipStrExpandEnv( fileLocal );
		FILE* fs = fopen( path.getString(), "wb" );
		if (!fs) 
			return FALSE;

		fseek( fs, offset, SEEK_SET );
		r = fwrite(imageBufferPtr, 1, image.bufferSize(), fs );

		fclose( fs );
	}
	image.unrefBufferPtr();

	return (r == image.bufferSize());
}
void
SoXipImageOverlayManager::loadOverlays()
{
	// When the patient changes
	clearClipboard();

	// Remove all the geometries from the switch
	mShapeSwitch->removeAllChildren();
	mShapeSwitch->whichChild.setValue(-1);

	mCurrentSlice = -1;

	if( mImageData )
	{
		SbString overlayStr = mImageData->getProperty( "overlays" );
		SoNodeList nodes = XipOverlayUtils::loadOverlaysFromString( overlayStr.getString(), overlayStr.getLength(), TRUE );

		for( int i = 0; i < nodes.getLength(); ++ i )
		{
			if( !nodes[i]->isOfType( SoXipShapeList::getClassTypeId() ) )
			{
				SoDebugError::post( __FILE__, "Invalid overlay node found in Dicom. Ignored." );				
				continue ;
			}
			mShapeSwitch->addChild( nodes[i] );
		}
	}

	updateSliceMap();
}
// Documented in superclass. Overridden to pass GL state to the
// previous element.
void
SoGLMultiTextureImageElement::pop(SoState * state,
                                  const SoElement * prevTopElement)
{
  inherited::pop(state, prevTopElement);
  SoGLMultiTextureImageElement * prev = (SoGLMultiTextureImageElement*)
    prevTopElement;

  SoGLShaderProgram * prog = SoGLShaderProgramElement::get(state);
  SbString str;
  
  const int maxunits = SbMax(PRIVATE(prev)->unitdata.getLength(),
                             PRIVATE(this)->unitdata.getLength());

  for (int i = 0; i < maxunits; i++) {
    const GLUnitData & prevud = 
      (i < PRIVATE(prev)->unitdata.getLength()) ?
      PRIVATE(prev)->unitdata[i] :
      PRIVATE(prev)->defaultdata;
    
    const GLUnitData & thisud = 
      (i < PRIVATE(this)->unitdata.getLength()) ?
      PRIVATE(this)->unitdata[i] :
      PRIVATE(this)->defaultdata;

    if (thisud.glimage != prevud.glimage) this->updateGL(i);
    str.sprintf("coin_texunit%d_model", i);
    if (prog) prog->updateCoinParameter(state, SbName(str.getString()),
                                        thisud.glimage != NULL ? this->getUnitData(i).model : 0);
  }
}
Ejemplo n.º 8
0
void IKRRTWindow::saveScreenshot()
{
    static int counter = 0;
    SbString framefile;

    framefile.sprintf("renderFrame_%06d.png", counter);
    counter++;
    redraw();
    viewer->getSceneManager()->render();
    viewer->getSceneManager()->scheduleRedraw();
    QGLWidget* w = (QGLWidget*)viewer->getGLWidget();

    QImage i = w->grabFrameBuffer();
    bool bRes = i.save(framefile.getString(), "BMP");

    if (bRes)
    {
        cout << "wrote image " << counter << endl;
    }
    else
    {
        cout << "failed writing image " << counter << endl;
    }

}
int SoXipGLSLShaderProgramElement::getProgramID(SoState * const state,
                                                const SbString & prgTag)
{
    ShaderProgramManager * manager = ShaderProgramManager::getInstance();
    int prgHandle = manager->getProgramHandle(prgTag.getString());

    return prgHandle;
}
__uint64 SoXipGLSLShaderProgramElement::getTimeStamp(SoState * const state,
                                                const SbString & prgTag)
{
    ShaderProgramManager * manager = ShaderProgramManager::getInstance();
    __uint64 time = manager->getTimeStamp(prgTag.getString());

    return time;
}
Ejemplo n.º 11
0
void SoXipGLSLPrograms::setTimeStamps(ShaderBatch * batch, const SbString& filename)
{
    if (!batch)
        return;

    int tod = ShaderEngine::getSourceFileTimeStamp(filename.getString());
    batch->source.setSourceTimeStamp(tod);

    batch->dirtyTimestamp = false;
}
Ejemplo n.º 12
0
void
SoHandleBoxDragger::updateSwitches(void)
{
  int i;
  SbString str;
  SoSwitch *sw;

  if (this->whatkind == WHATKIND_UNIFORM) {
    if (this->ctrlDown) {
      const int *ptr = uniform_ctrl_lookup[this->whatnum-1];
      for (i = 0; i < 6; i++) {
        str.sprintf("extruder%dSwitch", ptr[i]);
        sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch);
        SoInteractionKit::setSwitchValue(sw, i < 3 ? 1 : 0);
      }
    }
    else {
      for (i = 1; i <= 6; i++) {
        str.sprintf("extruder%dSwitch", i);
        sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch);
        SoInteractionKit::setSwitchValue(sw, 1);
      }
    }
    str.sprintf("uniform%dSwitch", this->whatnum);
    sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch);
    SoInteractionKit::setSwitchValue(sw, 1);
  }
  else if (this->whatkind == WHATKIND_EXTRUDER) {
    int othernum = ((this->whatnum-1) & ~1) + 1;
    if (othernum == this->whatnum) othernum++;

    str.sprintf("extruder%dSwitch", this->whatnum);
    sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch);
    SoInteractionKit::setSwitchValue(sw, 1);
    str.sprintf("extruder%dSwitch", othernum);
    sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch);
    SoInteractionKit::setSwitchValue(sw, this->ctrlDown ? 0 : 1);
  }
  else {
    this->setAllPartsActive(TRUE);
    this->updateArrows();
  }
}
int SoXipGLSLShaderProgramElement::set(SoState * const state,
                                       const SbString & prgTag)
{
    ShaderProgramManager * manager = ShaderProgramManager::getInstance();
    int prgHandle = manager->getProgramHandle(prgTag.getString());

    SoInt32Element::set(classStackIndex, state, prgHandle);

    return prgHandle;
}
Ejemplo n.º 14
0
void
errorHandlerCB(const SoError * error, void * data)
{
	if (pipeErrorMessagesToConsole) {
		(void)printf("%s\n", error->getDebugString().getString());
	}
	else {
		SbString debugstring = error->getDebugString();
		::MessageBox(NULL, CHAR_TO_NATIVE(debugstring.getString()), TEXT("SoError"), MB_OK | MB_ICONERROR);
	}
}
Ejemplo n.º 15
0
SbBool
SoTexture2::readImage(const SbString& fname, int &w, int &h, int &nc, 
		      unsigned char *&bytes)
//
////////////////////////////////////////////////////////////////////////
{
    w = h = nc = 0;
    bytes = NULL;
    
    // Empty file means an empty image...
    if (fname.getString()[0] == '\0')
	return TRUE;

    SoInput in;
    if (!in.openFile(fname.getString(), TRUE)) {
	return FALSE;
    }

#ifdef DEBUG
    SoDebugError::postInfo("SoTexture2::readImage",
			   "Reading texture image %s",
			   fname.getString());
#endif

    if (ReadSGIImage(in, w, h, nc, bytes))
	return TRUE;

    // fiopen() closes the file even if it can't read the data, so 
    // reopen it
    in.closeFile();
    if (!in.openFile(fname.getString(), TRUE))
	return FALSE;

    if (ReadGIFImage(in, w, h, nc, bytes))
	return TRUE;

    if (ReadJPEGImage(in, w, h, nc, bytes))
	return TRUE;

    return FALSE;
}
Ejemplo n.º 16
0
/*!
  Sets the current texture. Id \a didapply is TRUE, it is assumed
  that the texture image already is the current GL texture. Do not
  use this feature unless you know what you're doing.
*/
void
SoGLMultiTextureImageElement::set(SoState * const state, SoNode * const node,
                                  const int unit,
                                  SoGLImage * image,
                                  Model model,
                                  const SbColor & blendColor)
{
  SoGLMultiTextureImageElement * elem = (SoGLMultiTextureImageElement*)
    state->getElement(classStackIndex);

  PRIVATE(elem)->ensureCapacity(unit);
  GLUnitData & ud = PRIVATE(elem)->unitdata[unit];
  
  // FIXME: buggy. Find some solution to handle this. pederb, 2003-11-12
  // if (ud.glimage && ud.glimage->getImage()) ud.glimage->getImage()->readUnlock();

  if (image) {
    // keep SoMultiTextureImageElement "up-to-date"
    inherited::set(state, node,
                   unit,
                   SbVec3s(0,0,0),
                   0,
                   NULL,
                   multi_translateWrap(image->getWrapS()),
                   multi_translateWrap(image->getWrapT()),
                   multi_translateWrap(image->getWrapR()),
                   model,
                   blendColor);
    ud.glimage = image;
    // make sure image isn't changed while this is the active texture
    // FIXME: buggy. Find some solution to handle this. pederb, 2003-11-12
    // if (image->getImage()) image->getImage()->readLock();
  }
  else {
    ud.glimage = NULL;
    inherited::setDefault(state, node, unit);
  }
  elem->updateGL(unit);

  // FIXME: check if it's possible to support for other units as well
  if ((unit == 0) && image && image->isOfType(SoGLBigImage::getClassTypeId())) {
    SoShapeStyleElement::setBigImageEnabled(state, TRUE);
  }
  SoShapeStyleElement::setTransparentTexture(state,
                                             SoGLMultiTextureImageElement::hasTransparency(state));
  
  SoGLShaderProgram * prog = SoGLShaderProgramElement::get(state);
  if (prog) {
    SbString str;
    str.sprintf("coin_texunit%d_model", unit);
    prog->updateCoinParameter(state, SbName(str.getString()), ud.glimage ? model : 0);
  }
}
Ejemplo n.º 17
0
LRESULT
SoSimple::onQuit(HWND window, UINT message, WPARAM wparam, LPARAM lparam)
{
	if (idleSensorId != 0) ::KillTimer(NULL, idleSensorId);
	if (timerSensorId != 0) ::KillTimer(NULL, timerSensorId);
	if (delaySensorId != 0) ::KillTimer(NULL, delaySensorId);

	idleSensorId = timerSensorId = delaySensorId = 0;

	::UnregisterClass(CHAR_TO_NATIVE(gClassName.getString()), NULL);
	return 0;
}
Ejemplo n.º 18
0
QVariant ParametersItem::data ( int role ) const
{
	if( role == Qt::DisplayRole )
	{
		if ( column() == 0 ) return m_text;

		SbString fieldValue = "null";
		m_pField->get( fieldValue );
		return QString( fieldValue.getString() );
	}
	else
		return QStandardItem::data( role );
}
void SoView2DLiftChart::drawSliceIndicator(int x1, int x2, int y, int slice) {
   glColor3f(1, 1, 1);
   glBegin(GL_LINES);
   glVertex2f(x1,     y - 1);
   glVertex2f(x2 + 6, y - 1);
   glEnd();

   // convert float distance to string
   SbString sliceString = float(slice);

   View2DFont* font = SoView2D::globalFont(_dsl->getCurrentCacheContext());
   float fcolor[4] = {color.getValue()[0],color.getValue()[1],color.getValue()[2],1};
   font->drawString(x2 + 10, y - 6, 12, fcolor, sliceString.getString(), 0, true);
}
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 );
		}
	}
}
Ejemplo n.º 21
0
bool SoMap2ImagePt::getMappingPoint(int pt[2], SbString &uid, SbVec3f point)
{
	int depth = refInput.getNum();

	int slice = (int)(point[2] * depth);
	if (slice < 0 || slice >= depth)
		return false;

	SoXipDataDicom *dicom = refInput[slice];
	if (dicom){
		if (!dicom->getDataset().isNull()){
			SbXipDicomItem dataset(dicom->getDataset());

			//sop instance UID
			dataset.findAndGet(SbXipDicomTagKey(0x08, 0x18), uid, true);

			SbString imageCols;
			//image col
			dataset.findAndGet(SbXipDicomTagKey(0x0028, 0x0011), imageCols, true);

			SbString imageRows;
			//image row
			dataset.findAndGet(SbXipDicomTagKey(0x0028, 0x0010), imageRows, true);

			int col = atoi(imageCols.getString());
			int row = atoi(imageRows.getString());

			pt[0] = (int)(point[0] * col + 0.5);
			pt[1] = (int)(point[1] * row + 0.5);

			return true;
		}
	}
	
	return false;
}
Ejemplo n.º 22
0
/*!
  Activate or deactive all dragger geometry parts.
*/
void
SoHandleBoxDragger::setAllPartsActive(SbBool onoroff)
{
  int i;
  int val = onoroff ? 1 : 0;
  SoSwitch *sw;
  SbString str;
  for (i = 1; i <= 6; i++) {
    str.sprintf("translator%dSwitch", i);
    sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch);
    SoInteractionKit::setSwitchValue(sw, val);
  }
  for (i = 1; i <= 6; i++) {
    str.sprintf("extruder%dSwitch", i);
    sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch);
    SoInteractionKit::setSwitchValue(sw, val);
  }
  for (i = 1; i <= 8; i++) {
    str.sprintf("uniform%dSwitch", i);
    sw = SO_GET_ANY_PART(this, str.getString(), SoSwitch);
    SoInteractionKit::setSwitchValue(sw, val);
  }
  this->updateArrows();
}
Ejemplo n.º 23
0
bool SoXipGLSLPrograms::checkTimeStamps(ShaderBatch * batch, const SbString& filename)
{
    if (!batch)
        return false;

    bool dirty = false; 

    int tod = ShaderEngine::getSourceFileTimeStamp(filename.getString());
    int sts = batch->source.getSourceTimeStamp();
    if (tod > sts)
        dirty = true;

    batch->dirtyTimestamp = dirty;
    return dirty;
}
Ejemplo n.º 24
0
void QCtkXipSGWidget::updateCursor(bool fromScene)
{
  if (fromScene)
  {
    if (!mCursorField)
    {
      mCursorField = SoDB::getGlobalField(SbName("MouseCursor"));
    }

    if (mCursorField)
    {
      SbString str;
      mCursorField->get(str);

      const char *handlePtr = strstr(str.getString(), "handle\t");
      if (handlePtr)
      {
        void *handle = 0;
        if (sscanf(handlePtr, "handle\t%p", &handle) == 1)
        {
          if (handle)
          {
#ifdef WIN32
            setCursor(QCursor((HCURSOR) handle));
#endif /* WIN32 */

#ifdef linux
            setCursor(QCursor((Qt::HANDLE) handle));
#endif /* LINUX */

#ifdef DARWIN
            setCursor(QCursor()); // FIXME: We must create a handle for Mac OS X
#endif /* DARWIN */

            return;
          }
        }
      }
    }
  }

  setCursor(Qt::ArrowCursor);
}
Ejemplo n.º 25
0
SbBool
ImageReader::readImage(const SbString & filename, SbImage & sbimage) const
{
  QImage image;
  if (image.load(filename.getString())) {
    //int c;
    //int w = image.width();
    //int h = image.height();

    // Keep in 8-bits mode if that was what we read
    if (image.depth() != 8 || !image.isGrayscale()) {
      // FIXME: consider if we should detect allGrayscale() and alpha (c = 2)
      image = image.convertToFormat(image.hasAlphaChannel() ?
                                    QImage::Format_ARGB32 : QImage::Format_RGB32);
    }

    QtCoinCompatibility::QImageToSbImage(image,sbimage);
    return true;
  }
  return false;
}
Ejemplo n.º 26
0
/**
 *	Concatenates all componets into batch->vSource/gSource/fSource.
 */	
bool SoXipGLSLPrograms::updateSingleShader(ShaderBatch * batch, const SbString& filename, const SbString& defines, std::string& errstr)
{
    if (!batch)
        return false;

    std::string funcs = "";
    int shaderType = batch->source.getType();

    // Add the version string to the source file
    std::string s;
    switch(glslVersion.getValue())
    {
    default:
    case AUTO_SELECT:
        break;
    case V110:
        s += "#version 110 \n\n";
        break;
    case V120:
        s += "#version 120 \n\n";
        break;
    case V130:
        s += "#version 130 \n\n";
        break;
    case V140:
        s += "#version 140 \n\n";
        break;
    case V150:
        s += "#version 150 \n\n";
        break;
    }
    batch->source.addToSuppHeader(s.c_str());

    std::string defstr(defines.getString());
    std::string tmp, defVal;
    int p0 = 0;
    int p1 = 0;
    int d = defstr.find_first_not_of(",");
    while (d != defstr.npos)
    {
        p1 = defstr.find_first_of(",", p0);
        defVal = defstr.substr(p0,p1-p0);
        if (!defVal.empty() && defVal.find_first_not_of(" ") != defVal.npos)
        {
            tmp = std::string("#define ") + defVal;
            batch->source.addToSuppHeader(tmp.c_str());
        }
        p0 = p1+1;
        d  = p1;
    }

    batch->source.addToSuppHeader(ShaderEngine::readShaderSourceFile(filename.getString()).c_str());
    batch->handle = ShaderEngine::compileShader(batch->source.getFullComponent(), shaderType, errstr);
    //batch->timestamp = (batch->handle) ? time(NULL) : 0;
#ifdef WIN32
    batch->timestamp = (batch->handle) ? QueryPerformanceCounter((LARGE_INTEGER*)&batch->timestamp) : 0;
#else //UNIX
    if (!(batch->handle))
    {
        batch->timestamp = 0;
    }
    else
    {
        struct timeval curTime;
        gettimeofday(&curTime, NULL);
        //batch->timestamp = ((int64_t)curTime.tv_sec * (1000*1000) + (int64_t)curTime.tv_usec);
        batch->timestamp = (int64_t)curTime.tv_sec;
    }
#endif //WIN32
    if (!errstr.empty())
        return false;

    return true;
}
Ejemplo n.º 27
0
	bool operator()( const SbString& s1, const SbString& s2 ) const
	{
		return strcmp( s1.getString(), s2.getString() ) < 0;
	}
Ejemplo n.º 28
0
void
SoBuiltinFieldConverter::doConversion(SoField *outField)
//
////////////////////////////////////////////////////////////////////////
{
    // Various variables needed by the conversion cases:
    int i;
    SbMatrix matrix;
    SbString string;

    // Combine inType/outType into one integer.
    switch (inType*MAXFIELDS + outType) {

#define CASE(typeIn,typeOut) case typeIn*MAXFIELDS+typeOut

// This macro is for converting the single/multi fields into their
// corresponding multi/single value fields.
// In normal code, it looks like:
// Single to Multi:
//   SoMField->setValue(SoSField->getValue())
// Multi so Single:
//   if (MField->getNum() > 0) SoSField->setValue(SoMField[0])

#define CONV1(type)							    \
      CASE(SO__CONCAT(SF,type),SO__CONCAT(MF,type)):		    \
	((SO__CONCAT(SoMF,type) *)outField)->setValue(			    \
	    ((SO__CONCAT(SoSF,type) *)input)->getValue());		    \
	break;								    \
      CASE(SO__CONCAT(MF,type),SO__CONCAT(SF,type)):		    \
	if (((SoMField *)input)->getNum() > 0)				    \
	    ((SO__CONCAT(SoSF,type) *)outField)->setValue(		    \
		(*(SO__CONCAT(SoMF,type) *)input)[0]);			    \
	break
	
// Cases for all the field types:
	CONV1(BitMask);
	CONV1(Bool);
	CONV1(Color);
	CONV1(Enum);
	CONV1(Float);
	CONV1(Int32);
	CONV1(Matrix);
	CONV1(Name);
	CONV1(Node);
	CONV1(Path);
	CONV1(Plane);
	CONV1(Rotation);
	CONV1(Short);
	CONV1(String);
	CONV1(Time);
	CONV1(UInt32);
	CONV1(UShort);
	CONV1(Vec2f);
	CONV1(Vec3f);
	CONV1(Vec4f);
#undef CONV1
	
//
// Conversions to/from a string for all field types.  The eight cases
// are:
// Single to/from Single string:
// Single to/from Multiple string:
// Multi to/from Single string:
//    input->get(string); outField->set(string);
// Multi to/from Multi string:
//    for (i = 0; i < ((SoMField *)input)->getNum(); i++) {
//       (SoMField *)input->get1(i, string);
//       (SoMField *)outField->set1(i, string);
//
// Note: we must use the SF/MFString->setValue() routines and not just
// plain set() in case there is whitespace in the string, since set()
// takes file format, and in the file format strings with whitespace
// must be quoted.
//
#define CONVSTR(type)							    \
      CASE(SO__CONCAT(SF,type),SFString):				    \
      CASE(SO__CONCAT(MF,type),SFString):				    \
	input->get(string);						    \
	((SoSFString *)outField)->setValue(string);			    \
	break;								    \
      CASE(SO__CONCAT(SF,type),MFString):				    \
	input->get(string);						    \
	((SoMFString *)outField)->set1Value(0,string);			    \
	break;								    \
      CASE(SO__CONCAT(MF,type),MFString):				    \
	for (i = 0; i < ((SoMField *)input)->getNum(); i++) {		    \
	    ((SoMField *)input)->get1(i, string);			    \
	    ((SoMFString *)outField)->set1Value(i, string);		    \
	}								    \
	break;								    \
      CASE(SFString,SO__CONCAT(SF,type)):				    \
      CASE(MFString,SO__CONCAT(SF,type)):				    \
      CASE(SFString,SO__CONCAT(MF,type)):				    \
	input->get(string);						    \
	outField->set(string.getString());				    \
	break;								    \
      CASE(MFString,SO__CONCAT(MF,type)):				    \
	for (i = 0; i < ((SoMField *)input)->getNum(); i++) {		    \
	    ((SoMField *)input)->get1(i, string);			    \
	    ((SoMField *)outField)->set1(i, string.getString());	    \
	}								    \
	break
	
// All types except string:
	CONVSTR(BitMask);
	CONVSTR(Bool);
	CONVSTR(Color);
	CONVSTR(Enum);
	CONVSTR(Float);
	CONVSTR(Int32);
	CONVSTR(Matrix);
	CONVSTR(Name);
	CONVSTR(Node);
	CONVSTR(Path);
	CONVSTR(Plane);
	CONVSTR(Rotation);
	CONVSTR(Short);
	CONVSTR(UInt32);
	CONVSTR(UShort);
	CONVSTR(Vec2f);
	CONVSTR(Vec3f);
	CONVSTR(Vec4f);
#undef CONVSTR

// Special case for time to string; if the time is great enough,
// format as a date:
      CASE(SFTime,SFString):
      {
	  SbTime t = ((SoSFTime *)input)->getValue();
	  if (t.getValue() > 3.15e7) string = t.formatDate();
	  else string = t.format();
	  ((SoSFString *)outField)->setValue(string);
      }
      break;
      CASE(SFTime,MFString):
      {
	  SbTime t = ((SoSFTime *)input)->getValue();
	  if (t.getValue() > 3.15e7) string = t.formatDate();
	  else string = t.format();
	  ((SoMFString *)outField)->set1Value(0, string);
      }
      break;
      CASE(MFTime,SFString):
      {
	  SbTime t = (*((SoMFTime *)input))[0];
	  if (t.getValue() > 3.15e7) string = t.formatDate();
	  else string = t.format();
	  ((SoSFString *)outField)->setValue(string);
      }
      break;
      CASE(MFTime,MFString):
      {
	  for (i = 0; i < ((SoMField *)input)->getNum(); i++) {
	      SbTime t = (*((SoMFTime *)input))[i];
	      if (t.getValue() > 3.15e7) string = t.formatDate();
	      else string = t.format();
	      ((SoMFString *)outField)->set1Value(i, string);
	  }
      }
      break;
      CASE(SFString,SFTime):
      CASE(MFString,SFTime):
      CASE(SFString,MFTime):
	input->get(string);
	outField->set(string.getString());
	break;
      CASE(MFString,MFTime):
	for (i = 0; i < ((SoMField *)input)->getNum(); i++) {
	    ((SoMField *)input)->get1(i, string);
	    ((SoMField *)outField)->set1(i, string.getString());
	}
      break;
      

// This macro will do most of the conversions, relying on the C++
// built-in type conversions.  It does all eight combinations of
// single/multi to single/multi conversions for two types that are
// different.  HALF_CONV does the conversions one-way, CONV does them
// both ways:
// Single to single: 
//   SoSField->setValue(SoSField->getValue());
// Multi to single:
//   if (SoMField->getNum() > 0) SoSField->setValue(SoMField[0])
// Single to multi:
//   SoMField->setValue(SoSField->getValue())
// Multi to multi:
//   for (i = 0; i < SoMField->getNum(); i++) {
//      SoMField->set1Value(i, SoMfield[i]);
//   }
//
#define HALF_CONV(typeIn,typeOut,valTypeOut)				      \
      CASE(SO__CONCAT(SF,typeIn),SO__CONCAT(SF,typeOut)):		      \
	((SO__CONCAT(SoSF,typeOut) *)outField)->setValue((valTypeOut)	      \
	    ((SO__CONCAT(SoSF,typeIn) *)input)->getValue());		      \
	break;								      \
      CASE(SO__CONCAT(MF,typeIn),SO__CONCAT(SF,typeOut)):		      \
	if (((SoMField *)input)->getNum() > 0)				      \
	    ((SO__CONCAT(SoSF,typeOut) *)outField)->setValue((valTypeOut)     \
		(*(SO__CONCAT(SoMF,typeIn) *)input)[0]);		      \
	break;								      \
      CASE(SO__CONCAT(SF,typeIn),SO__CONCAT(MF,typeOut)):		      \
	((SO__CONCAT(SoMF,typeOut) *)outField)->setValue((valTypeOut)	      \
	    ((SO__CONCAT(SoSF,typeIn) *)input)->getValue());		      \
	break;								      \
      CASE(SO__CONCAT(MF,typeIn),SO__CONCAT(MF,typeOut)):		      \
	for (i = 0; i < ((SoMField *)input)->getNum(); i++) {		      \
	    ((SO__CONCAT(SoMF,typeOut) *)outField)->set1Value(i,	      \
		(valTypeOut) (*(SO__CONCAT(SoMF,typeIn) *)input)[i]);	      \
	}								      \
	break

#define CONV(type1,valType1,type2,valType2)				      \
    HALF_CONV(type1,type2,valType2);					      \
    HALF_CONV(type2,type1,valType1)
	

// Simple conversions for most fields:

	CONV(Bool,SbBool,Float,float);
	CONV(Bool,SbBool,Int32,int32_t);
	CONV(Bool,SbBool,Short,short);
	CONV(Bool,SbBool,UInt32,uint32_t);
	CONV(Bool,SbBool,UShort,unsigned short);

	CONV(Color,const SbColor &,Vec3f,const SbVec3f &);

	CONV(Float,float,Int32,int32_t);
	CONV(Float,float,Short,short);
	CONV(Float,float,UInt32,uint32_t);
	CONV(Float,float,UShort,unsigned short);

	CONV(Int32,int32_t,Short,short);
	CONV(Int32,int32_t,UInt32,uint32_t);
	CONV(Int32,int32_t,UShort,unsigned short);

	CONV(Short,short,UInt32,uint32_t);
	CONV(Short,short,UShort,unsigned short);

	CONV(UInt32,uint32_t,UShort,unsigned short);

// Some wacky oddball conversions that we have to special-case:

// Float to time can be handled by regular code because SbTime has a
// constructor that takes a float, but time to float needs to be
// special-cased:
      HALF_CONV(Float, Time, float);

      CASE(SFTime, SFFloat):
	((SoSFFloat *)outField)->setValue(
	    ((SoSFTime *)input)->getValue().getValue());
	break;
      CASE(SFTime, MFFloat):
	((SoMFFloat *)outField)->setValue(
	    ((SoSFTime *)input)->getValue().getValue());
	break;
      CASE(MFTime, SFFloat):
	((SoSFFloat *)outField)->setValue(
	    (*(SoMFTime *)input)[0].getValue());
	break;
      CASE(MFTime, MFFloat):
	for (i = 0; i < ((SoMFTime *)input)->getNum(); i++) {
	    ((SoMFFloat *)outField)->set1Value(i,
		(*(SoMFTime *)input)[i].getValue());
	}
	break;
	    
      CASE(SFMatrix, SFRotation):
        ((SoSFRotation *) outField)->setValue(
	    SbRotation(((SoSFMatrix *) input)->getValue()));
	break;
      CASE(SFMatrix, MFRotation):
        ((SoMFRotation *) outField)->setValue(
	    SbRotation(((SoSFMatrix *) input)->getValue()));
	break;
      CASE(MFMatrix, SFRotation):
        ((SoSFRotation *) outField)->setValue(
	    SbRotation((* (SoMFMatrix *) input)[0]));
        break;
      CASE(MFMatrix, MFRotation):
	for (i = 0; i < ((SoMFMatrix *)input)->getNum(); i++) {
	    ((SoMFRotation *)outField)->set1Value(i,
		SbRotation((* (SoMFMatrix *) input)[i]));
	}
        break;

      CASE(SFRotation, SFMatrix):
	matrix.setRotate(((SoSFRotation *)input)->getValue());
	((SoSFMatrix *)outField)->setValue(matrix);
	break;
      CASE(SFRotation, MFMatrix):
	matrix.setRotate(((SoSFRotation *)input)->getValue());
	((SoSFMatrix *)outField)->setValue(matrix);
	break;
      CASE(MFRotation, SFMatrix):
	matrix.setRotate((*(SoMFRotation *)input)[0]);
	((SoSFMatrix *)outField)->setValue(matrix);
	break;
      CASE(MFRotation, MFMatrix):
	for (i = 0; i < ((SoMFRotation *)input)->getNum(); i++) {
	    matrix.setRotate((*(SoMFRotation *)input)[i]);
	    ((SoMFMatrix *)outField)->set1Value(i, matrix);
	}
	break;

      default:
#ifdef DEBUG
        SoDebugError::post("SoBuiltinFieldConverter::doConversion",
			   "Can't convert type %d to type %d\n",
			   inType, outType);
#endif
        break;
    }
}
Ejemplo n.º 29
0
Py::String ViewProviderPy::getIV(void) const
{
    SbString buf = buffer_writeaction(getViewProviderPtr()->getRoot());
    return Py::String(buf.getString());
}
Ejemplo n.º 30
0
void QXipIvWidget::updateCursor(bool fromScene)
{
	if (fromScene)
	{
		if (!m_cursorField)
		{
			m_cursorField = dynamic_cast<SoMFString*>(SoDB::getGlobalField(SbName("XipCursor")));
		}

		if (m_cursorField)
		{
			SbString newCursor;
			m_cursorField->get1(0, newCursor);

            if (strcmp(newCursor.getString(), "\"MOVE_LINE\"") == 0)
                setCursor(Qt::SizeAllCursor);
            else if (strcmp(newCursor.getString(), "\"MOVE\"") == 0)
                setCursor(Qt::SizeAllCursor);
            else if (strcmp(newCursor.getString(), "\"ROTATE_INPLANE\"") == 0)
                setCursor(Qt::OpenHandCursor);
            else if (strcmp(newCursor.getString(), "\"ROTATE_NORMAL_VR\"") == 0)
                setCursor(Qt::OpenHandCursor);
            else if (strcmp(newCursor.getString(), "\"SEL_ROTATE\"") == 0)
                setCursor(Qt::ArrowCursor);
            else if (strcmp(newCursor.getString(), "\"SEL_ROTATE_VR\"") == 0)
                setCursor(Qt::ArrowCursor);
            else if (strcmp(newCursor.getString(), "\"SEL_ZOOM\"") == 0)
                setCursor(Qt::SizeVerCursor);
            else if (strcmp(newCursor.getString(), "\"SEL_PAN\"") == 0)
                setCursor(Qt::ArrowCursor);
            else
            {
                setCursor(Qt::ArrowCursor);
//                qDebug() << newCursor.getString();
            }
        }

//			const char* handlePtr = strstr(str.getString(), "handle\t");
//			if (handlePtr)
//			{
//				void* handle = 0;
//				if (sscanf(handlePtr, "handle\t%p", &handle) == 1)
//				{
//					if (handle)
//					{
//#ifdef WIN32
//						setCursor(QCursor((HCURSOR) handle));
//#endif /* WIN32 */
//
//#ifdef linux
//						setCursor(QCursor((Qt::HANDLE) handle));
//#endif /* LINUX */
//
//#ifdef DARWIN
//						setCursor(QCursor()); // FIXME: We must create a handle for Mac OS X
//#endif /* DARWIN */
//
//						return;
//					}
//				}
//			}
//		}
	}

	//setCursor(Qt::ArrowCursor);
}