void DataDialog::slotEditMultiple() { int charWidth = fontMetrics().averageCharWidth(); int currentWidth = width(); int extensionWidth = extensionWidget()->width(); if (extensionWidth<charWidth*20) extensionWidth = charWidth*25; // FIXME: magic number hack... extensionWidget()->setVisible(!extensionWidget()->isVisible()); if (!extensionWidget()->isVisible()) { _tagString->setVisible(true); _shortName->setVisible(true); _tagStringAuto->setVisible(true); _nameLabel->setVisible(true); setMinimumWidth(currentWidth - extensionWidth); resize(currentWidth - extensionWidth, height()); _mode = Edit; _editMultipleButton->setText(tr("Edit Multiple >>")); emit editSingleMode(); } else { if (currentWidth<charWidth*50) currentWidth = charWidth*80; // FIXME: magic number hack... _tagString->setVisible(false); _shortName->setVisible(false); _tagStringAuto->setVisible(false); _nameLabel->setVisible(false); setMinimumWidth(currentWidth + extensionWidth); resize(currentWidth + extensionWidth, height()); _mode = EditMultiple; _editMultipleButton->setText(tr("<< Edit one %1").arg(_shortName->text())); emit editMultipleMode(); } clearModified(); }
void VrmlNodeTextureSample::render(Viewer *viewer) { // Check texture cache if (d_texObject) { viewer->insertTextureReference(d_texObject, 3, d_environment.get(), d_blendMode.get()); } else { if (width()) { d_texObject = viewer->insertTexture(width(), height(), 3, d_repeatS.get(), d_repeatT.get(), pix, "", true, d_environment.get(), d_blendMode.get(), d_anisotropy.get(), d_filterMode.get()); } } clearModified(); }
void VrmlNodeClippingPlane::render(Viewer *viewer) { if (!haveToRender()) return; if (d_clipObject && isModified()) { viewer->removeObject(d_clipObject); d_clipObject = 0; } checkAndRemoveNodes(viewer); if (d_clipObject) { viewer->insertReference(d_clipObject); } else if (d_children.size() > 0) { d_clipObject = viewer->beginObject(name(), 0, this); } if (d_global.get()) { if (d_enabled.get()) { osg::ClipPlane *cp = cover->getClipPlane(d_number.get()); float *pos = d_position.get(); float *ori = d_orientation.get(); osg::Quat q(ori[3], osg::Vec3(ori[0], ori[1], ori[2])); osg::Vec3 normal(0, -1, 0); normal = q * normal; osg::Plane p(normal, osg::Vec3(pos[0], -pos[2], pos[1])); // rotated 90 degrees cp->setClipPlane(p); cover->getObjectsRoot()->addClipPlane(cp); } else { osg::ClipPlane *cp = cover->getClipPlane(d_number.get()); cover->getObjectsRoot()->removeClipPlane(cp); } } else { if (d_children.size() > 0) { // Apply transforms viewer->setClip(d_position.get(), d_orientation.get(), d_number.get(), d_enabled.get()); } } if (d_children.size() > 0) { // Render children VrmlNodeGroup::render(viewer); viewer->endObject(); } clearModified(); }
void VrmlNodeTextureTransform::render(Viewer *viewer) { viewer->setTextureTransform( d_center.get(), d_rotation.get(), d_scale.get(), d_translation.get() ); clearModified(); }
void VrmlNodeMovieTexture::render(Viewer *viewer) { //theSystem->debug("MovieTexture.%s::render frame %d\n", name(), d_frame); if ( ! d_image || d_frame < 0 ) return; unsigned char *pix = d_image->pixels( d_frame ); if ( d_frame != d_lastFrame && d_texObject ) { viewer->removeTextureObject( d_texObject ); d_texObject = 0; } if ( ! pix ) { d_frame = -1; } else if ( d_texObject ) { viewer->insertTextureReference( d_texObject, d_image->nc() ); } else { // Ensure image dimensions are powers of 2 (move to VrmlNodeTexture...) int sizes[] = { 2, 4, 8, 16, 32, 64, 128, 256 }; int nSizes = sizeof(sizes) / sizeof(int); int w = d_image->w(); int h = d_image->h(); int i, j; for (i=0; i<nSizes; ++i) if (w < sizes[i]) break; for (j=0; j<nSizes; ++j) if (h < sizes[j]) break; if (i > 0 && j > 0) { // Always scale images down in size and reuse the same pixel memory. if (w != sizes[i-1] || h != sizes[j-1]) { viewer->scaleTexture( w, h, sizes[i-1], sizes[j-1], d_image->nc(), pix ); d_image->setSize( sizes[i-1], sizes[j-1] ); } d_texObject = viewer->insertTexture(d_image->w(), d_image->h(), d_image->nc(), d_repeatS.get(), d_repeatT.get(), pix, ! d_isActive.get() ); } } d_lastFrame = d_frame; clearModified(); }
void VrmlNodeSwitch::render(Viewer *viewer) { int w = d_whichChoice.get(); if (w >= 0 && w < d_choice.size()) d_choice[w]->render(viewer); clearModified(); }
void CVar::lock() { if (!isReadOnly()) return; if (m_allowedWrite) { m_flags |= ReadOnly; m_allowedWrite = false; clearModified(); } }
void Profile::save( MetaClient::Profile & profile ) { StatTree::Iterator iStat = m_Stats.head(); while( iStat.valid() ) { CharString sKey = iStat.key(); profile[ sKey ] = CharString().format("%f", (*iStat) ); iStat++; } clearModified(); }
void Cal3dNode::render(Viewer *v) { ViewerOsg *viewer = (ViewerOsg *)v; if (d_viewerObject) viewer->insertReference(d_viewerObject); else { d_viewerObject = viewer->beginObject(name(), 0, this); viewer->insertNode(myTransform.get()); viewer->endObject(); } clearModified(); }
void TextFile::saveAs(const std::string &fileName) { fileName_ = fileName; setName(toUtf16(baseName(fileName))); std::ofstream f(fileName_); bool first = true; for (const auto &l: buffer_) { if (first) first = false; else f << std::endl; f << toUtf8(l); } clearModified(); }
void VrmlNodeGeometry::render(Viewer *v) { if ( d_viewerObject && isModified() ) { v->removeObject(d_viewerObject); d_viewerObject = 0; } if (d_viewerObject) v->insertReference(d_viewerObject); else { d_viewerObject = insertGeometry(v); clearModified(); } }
void DataDialog::slotApply() { Kst::ObjectPtr ptr; if (!dataObject()) { ptr = createNewDataObject(); } else { ptr = editExistingDataObject(); } setDataObject(ptr); UpdateManager::self()->doUpdates(); UpdateServer::self()->requestUpdateSignal(); kstApp->mainWindow()->document()->setChanged(true); clearModified(); }
void DataDialog::slotApply() { Kst::ObjectPtr ptr; bool do_session_reset = false; if (!dataObject()) { ptr = createNewDataObject(); do_session_reset = true; } else { ptr = editExistingDataObject(); } setDataObject(ptr); UpdateManager::self()->doUpdates(); kstApp->mainWindow()->document()->setChanged(true); if (do_session_reset) { kstApp->mainWindow()->document()->session()->triggerReset(); } clearModified(); }
void Profile::load( const MetaClient::Profile & profile ) { m_nFlags = profile.flags; m_nUserId = profile.userId; m_nClanId = profile.clanId; m_nSessionId = profile.sessionId; m_sEmail = profile.email; m_sName = profile.name; m_Stats.release(); for(int i=0;i<profile.fields.size();++i) { const MetaClient::Field & field = profile.fields[ i ]; m_Stats[ field.name ] = atof( field.value ); } clearModified(); }
void VrmlNodeAppearance::render(Viewer *viewer) { VrmlNodeMaterial *m = d_material.get() ? d_material.get()->toMaterial() : 0; VrmlNodeTexture *t = d_texture.get() ? d_texture.get()->toTexture() : 0; if (m) { float trans = m->transparency(); float *diff = m->diffuseColor(); float diffuse[3] = { diff[0], diff[1], diff[2] }; int nTexComponents = t ? t->nComponents() : 0; if (nTexComponents == 2 || nTexComponents == 4) trans = 0.0; if (nTexComponents >= 3) diffuse[0] = diffuse[1] = diffuse[2] = 1.0; viewer->setMaterial(m->ambientIntensity(), diffuse, m->emissiveColor(), m->shininess(), m->specularColor(), trans); m->clearModified(); } else { viewer->setColor(1.0, 1.0, 1.0); // default color viewer->enableLighting(false); // turn lighting off for this object } if (t) { if (d_textureTransform.get()) d_textureTransform.get()->render(viewer); else viewer->setTextureTransform( 0, 0, 0, 0 ); t->render(viewer); } clearModified(); }
void VrmlScene::render(Viewer *viewer) { // if (d_newView) { viewer->resetUserNavigation(); d_newView = false; } // Default viewpoint parameters float position[3] = { 0.0, 0.0, 10.0 }; float orientation[4] = { 0.0, 0.0, 1.0, 0.0 }; float field = 0.785398; float avatarSize = 0.25; float visibilityLimit = 0.0; VrmlNodeViewpoint *vp = bindableViewpointTop(); if (vp) { position[0] = vp->positionX(); position[1] = vp->positionY(); position[2] = vp->positionZ(); orientation[0] = vp->orientationX(); orientation[1] = vp->orientationY(); orientation[2] = vp->orientationZ(); orientation[3] = vp->orientationR(); field = vp->fieldOfView(); vp->inverseTransform(viewer); } VrmlNodeNavigationInfo *ni = bindableNavigationInfoTop(); if (ni) { avatarSize = ni->avatarSize()[0]; visibilityLimit = ni->visibilityLimit(); } viewer->setViewpoint( position, orientation, field, avatarSize, visibilityLimit); // Set background. VrmlNodeBackground *bg = bindableBackgroundTop(); if (bg) { // Should be transformed by the accumulated rotations above ... bg->renderBindable(viewer); } else viewer->insertBackground(); // Default background // Fog VrmlNodeFog *f = bindableFogTop(); if (f) { viewer->setFog(f->color(), f->visibilityRange(), f->fogType()); } // Activate the headlight. // ambient is supposed to be 0 according to the spec... if ( headlightOn() ) { float rgb[3] = { 1.0, 1.0, 1.0 }; float xyz[3] = { 0.0, 0.0, -1.0 }; float ambient = 0.3; viewer->insertDirLight( ambient, 1.0, rgb, xyz ); } // Top level object viewer->beginObject(0); // Do the scene-level lights (Points and Spots) VrmlNodeList::iterator li, end = d_scopedLights->end(); for (li = d_scopedLights->begin(); li != end; ++li) { VrmlNodeLight* x = (*li)->toLight(); if (x) x->renderScoped( viewer ); } // Render the top level group d_nodes.render( viewer ); viewer->endObject(); // This is actually one frame late... d_frameRate = viewer->getFrameRate(); clearModified(); // If any events were generated during render (ugly...) do an update if (eventsPending()) setDelta( 0.0 ); }
void VrmlNodeCoordinateInt::eventIn(double timeStamp, const char *eventName, const VrmlField *fieldValue) { if (strcmp(eventName, "set_fraction") == 0) { if (! fieldValue->toSFFloat() ) { theSystem->error ("Invalid type for %s eventIn %s (expected SFFloat).\n", nodeType()->getName(), eventName); return; } float f = fieldValue->toSFFloat()->get(); int nCoords = d_keyValue.size() / d_key.size(); int n = d_key.size() - 1; if (f < d_key[0]) { d_value.set( nCoords, d_keyValue[0] ); } else if (f > d_key[n]) { d_value.set( nCoords, d_keyValue[n*nCoords] ); } else { // Reserve enough space for the new value d_value.set( nCoords, 0 ); for (int i=0; i<n; ++i) if (d_key[i] <= f && f <= d_key[i+1]) { float *v1 = d_keyValue[i*nCoords]; float *v2 = d_keyValue[(i+1)*nCoords]; float *x = d_value.get(); f = (f - d_key[i]) / (d_key[i+1] - d_key[i]); for (int j=0; j<nCoords; ++j) { *x++ = v1[0] + f * (v2[0] - v1[0]); *x++ = v1[1] + f * (v2[1] - v1[1]); *x++ = v1[2] + f * (v2[2] - v1[2]); v1 += 3; v2 += 3; } break; } } // Send the new value eventOut(timeStamp, "value_changed", d_value); } // Check exposedFields else { VrmlNode::eventIn(timeStamp, eventName, fieldValue); // This node is not renderable, so don't re-render on changes to it. clearModified(); } }
void VrmlNodeVisibilitySensor::render(Viewer *viewer) { if (d_enabled.get()) { VrmlSFTime timeNow( theSystem->time() ); float xyz[2][3]; // hack: enclose box in a sphere... xyz[0][0] = d_center.x(); xyz[0][1] = d_center.y(); xyz[0][2] = d_center.z(); xyz[1][0] = d_center.x() + d_size.x(); xyz[1][1] = d_center.y() + d_size.y(); xyz[1][2] = d_center.z() + d_size.z(); viewer->transformPoints( 2, &xyz[0][0] ); float dx = xyz[1][0]-xyz[0][0]; float dy = xyz[1][1]-xyz[0][1]; float dz = xyz[1][2]-xyz[0][2]; float r = dx*dx + dy*dy + dz*dz; if (! FPZERO(r) ) r = sqrt( r ); // Was the sphere visible last time through? How does this work // for USE'd nodes? I need a way for each USE to store whether // it was active. bool wasIn = d_isActive.get(); // Is the sphere visible? ... bool inside = xyz[0][2] < 0.0; // && z > - scene->visLimit() if (inside) { VrmlNodeNavigationInfo *ni = d_scene->bindableNavigationInfoTop(); if (ni && ! FPZERO(ni->visibilityLimit()) && xyz[0][2] < - ni->visibilityLimit()) inside = false; } // This bit assumes 90degree fieldOfView to get rid of trig calls... if (inside) inside = ( fabs(double(xyz[0][0])) < -0.5 * xyz[0][2] + r && fabs(double(xyz[0][1])) < -0.5 * xyz[0][2] + r ); // Just became visible if (inside && ! wasIn) { theSystem->debug("VS enter %g, %g, %g\n", xyz[0][0], xyz[0][1], xyz[0][2]); d_isActive.set(true); eventOut(timeNow.get(), "isActive", d_isActive); d_enterTime = timeNow; eventOut(timeNow.get(), "enterTime", d_enterTime); } // Check if viewer has left the box else if (wasIn && ! inside) { theSystem->debug("VS exit %g, %g, %g\n", xyz[0][0], xyz[0][1], xyz[0][2]); d_isActive.set(false); eventOut(timeNow.get(), "isActive", d_isActive ); d_exitTime = timeNow; eventOut(timeNow.get(), "exitTime", d_exitTime); } } else clearModified(); }
void VrmlNodeOrientationInt::eventIn(double timeStamp, const char *eventName, const VrmlField *fieldValue) { if (strcmp(eventName, "set_fraction") == 0) { if (! fieldValue->toSFFloat() ) { theSystem->error ("Invalid type for %s eventIn %s (expected SFFloat).\n", nodeType()->getName(), eventName); return; } float f = fieldValue->toSFFloat()->get(); //printf("OI.set_fraction %g ", f); int n = d_key.size() - 1; if (f < d_key[0]) { float *v0 = d_keyValue[0]; //printf(" 0 [%g %g %g %g]\n", v0[0], v0[1], v0[2], v0[3] ); d_value.set( v0[0], v0[1], v0[2], v0[3] ); } else if (f > d_key[n]) { float *vn = d_keyValue[n]; //printf(" n [%g %g %g %g]\n", vn[0], vn[1], vn[2], vn[3] ); d_value.set( vn[0], vn[1], vn[2], vn[3] ); } else { for (int i=0; i<n; ++i) if (d_key[i] <= f && f <= d_key[i+1]) { float *v1 = d_keyValue[i]; float *v2 = d_keyValue[i+1]; // Interpolation factor f = (f - d_key[i]) / (d_key[i+1] - d_key[i]); float x, y, z, r1, r2; r1 = v1[3]; // Make sure the vectors are not pointing opposite ways if (v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2] < 0.0) { x = v1[0] + f * (-v2[0] - v1[0]); y = v1[1] + f * (-v2[1] - v1[1]); z = v1[2] + f * (-v2[2] - v1[2]); r2 = -v2[3]; } else { x = v1[0] + f * (v2[0] - v1[0]); y = v1[1] + f * (v2[1] - v1[1]); z = v1[2] + f * (v2[2] - v1[2]); r2 = v2[3]; } // Interpolate angles via the shortest direction if (fabs(double(r2 - r1)) > M_PI) { if (r2 > r1) r1 += 2.0 * M_PI; else r2 += 2.0 * M_PI; } float r = r1 + f * (r2 - r1); if (r >= 2.0 * M_PI) r -= 2.0 * M_PI; else if (r < 0.0) r += 2.0 * M_PI; //printf(" %g between (%d,%d) [%g %g %g %g]\n", f, i, i+1, //x, y, z, r); d_value.set( x, y, z, r); break; } } // Send the new value eventOut(timeStamp, "value_changed", d_value); } // Check exposedFields else { VrmlNode::eventIn(timeStamp, eventName, fieldValue); // This node is not renderable, so don't re-render on changes to it. clearModified(); } }