QString QgsMapToolLabel::currentLabelText() { QgsVectorLayer* vlayer = currentLayer(); if ( !vlayer ) { return ""; } QString labelField = vlayer->customProperty( "labeling/fieldName" ).toString(); if ( !labelField.isEmpty() ) { int labelFieldId = vlayer->fieldNameIndex( labelField ); QgsFeature f; if ( vlayer->featureAtId( mCurrentLabelPos.featureId, f, false, true ) ) { return f.attributeMap()[labelFieldId].toString(); } } return ""; }
QgsPalLayerSettings& QgsMapToolLabel::currentLabelSettings( bool* ok ) { QgsVectorLayer* vlayer = currentLayer(); if ( vlayer ) { QgsPalLabeling* labelEngine = dynamic_cast<QgsPalLabeling*>( mCanvas->mapRenderer()->labelingEngine() ); if ( labelEngine ) { if ( ok ) { *ok = true; } return labelEngine->layer( mCurrentLabelPos.layerID ); } } if ( ok ) { *ok = false; } return mInvalidLabelSettings; }
bool QgsMapToolLabel::isPinned() { bool rc = false; if ( ! mCurrentLabelPos.isDiagram ) { rc = mCurrentLabelPos.isPinned; } else { // for diagrams, the isPinned attribute is not set. So we check directly if // there's data defined. int xCol, yCol; double x, y; bool xSuccess, ySuccess; if ( dataDefinedPosition( currentLayer(), mCurrentLabelPos.featureId, x, xSuccess, y, ySuccess, xCol, yCol ) && xSuccess && ySuccess ) rc = true; } return rc; }
void QgsMapLayerComboBox::indexChanged( int i ) { Q_UNUSED( i ); QgsMapLayer *layer = currentLayer(); emit layerChanged( layer ); }
QFont QgsMapToolLabel::labelFontCurrentFeature() { QFont font; QgsVectorLayer* vlayer = currentLayer(); bool labelSettingsOk; QgsPalLayerSettings& labelSettings = currentLabelSettings( &labelSettingsOk ); if ( labelSettingsOk && vlayer ) { font = labelSettings.textFont; QgsFeature f; if ( vlayer->getFeatures( QgsFeatureRequest().setFilterFid( mCurrentLabelPos.featureId ).setFlags( QgsFeatureRequest::NoGeometry ) ).nextFeature( f ) ) { //size int sizeIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Size, vlayer ); if ( sizeIndx != -1 ) { if ( labelSettings.fontSizeInMapUnits ) { font.setPixelSize( labelSettings.sizeToPixel( f.attribute( sizeIndx ).toDouble(), QgsRenderContext(), QgsPalLayerSettings::MapUnits, true ) ); } else { font.setPointSizeF( f.attribute( sizeIndx ).toDouble() ); } } //family int fmIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Family, vlayer ); if ( fmIndx != -1 ) { font.setFamily( f.attribute( fmIndx ).toString() ); } //underline int ulIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Underline, vlayer ); if ( ulIndx != -1 ) { font.setUnderline( f.attribute( ulIndx ).toBool() ); } //strikeout int soIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Strikeout, vlayer ); if ( soIndx != -1 ) { font.setStrikeOut( f.attribute( soIndx ).toBool() ); } //bold int boIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Bold, vlayer ); if ( boIndx != -1 ) { font.setBold( f.attribute( boIndx ).toBool() ); } //italic int itIndx = dataDefinedColumnIndex( QgsPalLayerSettings::Italic, vlayer ); if ( itIndx != -1 ) { font.setItalic( f.attribute( itIndx ).toBool() ); } // TODO: Add other font data defined values (word spacing, etc.) } } return font; }
bool usdWriteJob::beginJob(const std::string &iFileName, bool append, double startTime, double endTime) { // Check for DAG nodes that are a child of an already specified DAG node to export // if that's the case, report the issue and skip the export PxrUsdMayaUtil::ShapeSet::const_iterator m, n; PxrUsdMayaUtil::ShapeSet::const_iterator endPath = mArgs.dagPaths.end(); for (m = mArgs.dagPaths.begin(); m != endPath; ) { MDagPath path1 = *m; m++; for (n = m; n != endPath; n++) { MDagPath path2 = *n; if (PxrUsdMayaUtil::isAncestorDescendentRelationship(path1,path2)) { MString errorMsg = path1.fullPathName(); errorMsg += " and "; errorMsg += path2.fullPathName(); errorMsg += " have an ancestor relationship. Skipping USD Export."; MGlobal::displayError(errorMsg); return false; } } // for n } // for m // Make sure the file name is a valid one with a proper USD extension. const std::string iFileExtension = TfStringGetSuffix(iFileName, '.'); if (iFileExtension == PxrUsdMayaTranslatorTokens->UsdFileExtensionDefault || iFileExtension == PxrUsdMayaTranslatorTokens->UsdFileExtensionASCII || iFileExtension == PxrUsdMayaTranslatorTokens->UsdFileExtensionCrate) { mFileName = iFileName; } else { mFileName = TfStringPrintf("%s.%s", iFileName.c_str(), PxrUsdMayaTranslatorTokens->UsdFileExtensionDefault.GetText()); } MGlobal::displayInfo("usdWriteJob::beginJob: Create stage file "+MString(mFileName.c_str())); ArResolverContext resolverCtx = ArGetResolver().GetCurrentContext(); if (append) { mStage = UsdStage::Open(SdfLayer::FindOrOpen(mFileName), resolverCtx); if (!mStage) { MGlobal::displayError("Failed to open stage file "+MString(mFileName.c_str())); return false; } } else { mStage = UsdStage::CreateNew(mFileName, resolverCtx); if (!mStage) { MGlobal::displayError("Failed to create stage file "+MString(mFileName.c_str())); return false; } } // Set time range for the USD file mStage->SetStartTimeCode(startTime); mStage->SetEndTimeCode(endTime); mModelKindWriter.Reset(); // Setup the requested render layer mode: // defaultLayer - Switch to the default render layer before exporting, // then switch back afterwards (no layer switching if // the current layer IS the default layer). // currentLayer - No layer switching before or after exporting. Just // use whatever is the current render layer for export. // modelingVariant - Switch to the default render layer before exporting, // and export each render layer in the scene as a // modeling variant, then switch back afterwards (no // layer switching if the current layer IS the default // layer). The default layer will be made the default // modeling variant. MFnRenderLayer currentLayer(MFnRenderLayer::currentLayer()); mCurrentRenderLayerName = currentLayer.name(); if (mArgs.renderLayerMode == PxUsdExportJobArgsTokens->modelingVariant) { // Handle usdModelRootOverridePath for USD Variants MFnRenderLayer::listAllRenderLayers(mRenderLayerObjs); if (mRenderLayerObjs.length() > 1) { mArgs.usdModelRootOverridePath = SdfPath("/_BaseModel_"); } } // Switch to the default render layer unless the renderLayerMode is // 'currentLayer', or the default layer is already the current layer. if (mArgs.renderLayerMode != PxUsdExportJobArgsTokens->currentLayer && MFnRenderLayer::currentLayer() != MFnRenderLayer::defaultRenderLayer()) { // Set the RenderLayer to the default render layer MFnRenderLayer defaultLayer(MFnRenderLayer::defaultRenderLayer()); MGlobal::executeCommand(MString("editRenderLayerGlobals -currentRenderLayer ")+ defaultLayer.name(), false, false); } // Pre-process the argument dagPath path names into two sets. One set // contains just the arg dagPaths, and the other contains all parents of // arg dagPaths all the way up to the world root. Partial path names are // enough because Maya guarantees them to still be unique, and they require // less work to hash and compare than full path names. TfHashSet<std::string, TfHash> argDagPaths; TfHashSet<std::string, TfHash> argDagPathParents; PxrUsdMayaUtil::ShapeSet::const_iterator end = mArgs.dagPaths.end(); for (PxrUsdMayaUtil::ShapeSet::const_iterator it = mArgs.dagPaths.begin(); it != end; ++it) { MDagPath curDagPath = *it; std::string curDagPathStr(curDagPath.partialPathName().asChar()); argDagPaths.insert(curDagPathStr); while (curDagPath.pop() && curDagPath.length() >= 0) { curDagPathStr = curDagPath.partialPathName().asChar(); if (argDagPathParents.find(curDagPathStr) != argDagPathParents.end()) { // We've already traversed up from this path. break; } argDagPathParents.insert(curDagPathStr); } } // Now do a depth-first traversal of the Maya DAG from the world root. // We keep a reference to arg dagPaths as we encounter them. MDagPath curLeafDagPath; for (MItDag itDag(MItDag::kDepthFirst, MFn::kInvalid); !itDag.isDone(); itDag.next()) { MDagPath curDagPath; itDag.getPath(curDagPath); std::string curDagPathStr(curDagPath.partialPathName().asChar()); if (argDagPathParents.find(curDagPathStr) != argDagPathParents.end()) { // This dagPath is a parent of one of the arg dagPaths. It should // be included in the export, but not necessarily all of its // children should be, so we continue to traverse down. } else if (argDagPaths.find(curDagPathStr) != argDagPaths.end()) { // This dagPath IS one of the arg dagPaths. It AND all of its // children should be included in the export. curLeafDagPath = curDagPath; } else if (!MFnDagNode(curDagPath).hasParent(curLeafDagPath.node())) { // This dagPath is not a child of one of the arg dagPaths, so prune // it and everything below it from the traversal. itDag.prune(); continue; } MayaPrimWriterPtr primWriter = nullptr; if (!createPrimWriter(curDagPath, &primWriter) && curDagPath.length() > 0) { // This dagPath and all of its children should be pruned. itDag.prune(); continue; } if (primWriter) { mMayaPrimWriterList.push_back(primWriter); // Write out data (non-animated/default values). if (UsdPrim usdPrim = primWriter->write(UsdTimeCode::Default())) { MDagPath dag = primWriter->getDagPath(); mDagPathToUsdPathMap[dag] = usdPrim.GetPath(); // If we are merging transforms and the object derives from // MayaTransformWriter but isn't actually a transform node, we // need to add its parent. if (mArgs.mergeTransformAndShape) { MayaTransformWriterPtr xformWriter = boost::dynamic_pointer_cast<MayaTransformWriter>( primWriter); if (xformWriter) { MDagPath xformDag = xformWriter->getTransformDagPath(); mDagPathToUsdPathMap[xformDag] = usdPrim.GetPath(); } } mModelKindWriter.OnWritePrim(usdPrim, primWriter); if (primWriter->shouldPruneChildren()) { itDag.prune(); } } } } // Writing Materials/Shading PxrUsdMayaTranslatorMaterial::ExportShadingEngines( mStage, mArgs.dagPaths, mArgs.shadingMode, mArgs.mergeTransformAndShape, mArgs.usdModelRootOverridePath); if (!mModelKindWriter.MakeModelHierarchy(mStage)) { return false; } // now we populate the chasers and run export default mChasers.clear(); PxrUsdMayaChaserRegistry::FactoryContext ctx(mStage, mDagPathToUsdPathMap, mArgs); for (const std::string& chaserName : mArgs.chaserNames) { if (PxrUsdMayaChaserRefPtr fn = PxrUsdMayaChaserRegistry::GetInstance().Create(chaserName, ctx)) { mChasers.push_back(fn); } else { std::string error = TfStringPrintf("Failed to create chaser: %s", chaserName.c_str()); MGlobal::displayError(MString(error.c_str())); } } for (const PxrUsdMayaChaserRefPtr& chaser : mChasers) { if (!chaser->ExportDefault()) { return false; } } return true; }
void TimelineContainer::removeSelectionInCurrentLayer() { auto selection = currentSelection(); if (currentLayer() && selection.state() == Selection::DONE) currentLayer()->events().removeEventsInRange(selection.left(), selection.right()); }
void TimelineContainer::addEventToCurrentLayer(const std::shared_ptr<TimelineEvent> &event) { if (currentLayer()) currentLayer()->events().addEvent(event); }
// Layer management Layer* LayerManager::currentLayer() { return currentLayer( 0 ); }
void QgsMapToolLabel::createRubberBands() { delete mLabelRubberBand; delete mFeatureRubberBand; //label rubber band QgsRectangle rect = mCurrentLabelPos.labelRect; mLabelRubberBand = new QgsRubberBand( mCanvas, QGis::Line ); mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMaximum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMaximum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMaximum(), rect.yMinimum() ) ); mLabelRubberBand->addPoint( QgsPoint( rect.xMinimum(), rect.yMinimum() ) ); mLabelRubberBand->setColor( QColor( 0, 255, 0, 65 ) ); mLabelRubberBand->setWidth( 3 ); mLabelRubberBand->show(); //feature rubber band QgsVectorLayer* vlayer = currentLayer(); if ( vlayer ) { QgsFeature f; if ( currentFeature( f, true ) ) { const QgsGeometry* geom = f.constGeometry(); if ( geom ) { QSettings settings; int r = settings.value( "/qgis/digitizing/line_color_red", 255 ).toInt(); int g = settings.value( "/qgis/digitizing/line_color_green", 0 ).toInt(); int b = settings.value( "/qgis/digitizing/line_color_blue", 0 ).toInt(); int a = settings.value( "/qgis/digitizing/line_color_alpha", 200 ).toInt(); mFeatureRubberBand = new QgsRubberBand( mCanvas, geom->type() ); mFeatureRubberBand->setColor( QColor( r, g, b, a ) ); mFeatureRubberBand->setToGeometry( geom, vlayer ); mFeatureRubberBand->show(); } } //fixpoint rubber band QgsPoint fixPoint; if ( rotationPoint( fixPoint, false, false ) ) { if ( mCanvas ) { const QgsMapSettings& s = mCanvas->mapSettings(); if ( s.hasCrsTransformEnabled() ) { fixPoint = s.mapToLayerCoordinates( vlayer, fixPoint ); } } QgsGeometry* pointGeom = QgsGeometry::fromPoint( fixPoint ); mFixPointRubberBand = new QgsRubberBand( mCanvas, QGis::Line ); mFixPointRubberBand->setColor( QColor( 0, 0, 255, 65 ) ); mFixPointRubberBand->setToGeometry( pointGeom, vlayer ); mFixPointRubberBand->show(); delete pointGeom; } } }
void QgsMapToolPinLabels::pinUnpinLabels( const QgsRectangle& ext, QMouseEvent * e ) { bool doUnpin = e->modifiers() & Qt::ShiftModifier ? true : false; bool toggleUnpinOrPin = e->modifiers() & Qt::ControlModifier ? true : false; // get list of all drawn labels from all layers within, or touching, chosen extent bool labelChanged = false; const QgsLabelingResults* labelingResults = mCanvas->labelingResults(); if ( !labelingResults ) { QgsDebugMsg( QString( "No labeling engine" ) ); return; } QList<QgsLabelPosition> labelPosList = labelingResults->labelsWithinRect( ext ); QList<QgsLabelPosition>::const_iterator it; for ( it = labelPosList.constBegin() ; it != labelPosList.constEnd(); ++it ) { mCurrentLabelPos = *it; #ifdef QGISDEBUG QString labellyr = currentLayer()->name(); QString labeltxt = currentLabelText(); #endif QgsDebugMsg( QString( "Layer: %0" ).arg( labellyr ) ); QgsDebugMsg( QString( "Label: %0" ).arg( labeltxt ) ); QgsMapLayer* layer = QgsMapLayerRegistry::instance()->mapLayer( mCurrentLabelPos.layerID ); if ( !layer ) { QgsDebugMsg( QString( "Failed to get label layer" ) ); continue; } QgsVectorLayer* vlayer = dynamic_cast<QgsVectorLayer*>( layer ); if ( !vlayer ) { QgsDebugMsg( QString( "Failed to cast label layer to vector layer" ) ); continue; } if ( !vlayer->isEditable() ) { QgsDebugMsg( QString( "Vector layer not editable, skipping label" ) ); continue; } QString labelStringID = QString( "%0|%1" ).arg( mCurrentLabelPos.layerID, QString::number( mCurrentLabelPos.featureId ) ); // unpin label if ( mCurrentLabelPos.isPinned && ( doUnpin || toggleUnpinOrPin ) ) { // unpin previously pinned label (set attribute table fields to NULL) if ( pinUnpinLabel( vlayer, mCurrentLabelPos, false ) ) { labelChanged = true; } else { QgsDebugMsg( QString( "Unpin failed for layer, label: %0, %1" ).arg( labellyr, labeltxt ) ); } } // pin label if ( !mCurrentLabelPos.isPinned && ( !doUnpin || toggleUnpinOrPin ) ) { // pin label's location, and optionally rotation, to attribute table if ( pinUnpinLabel( vlayer, mCurrentLabelPos, true ) ) { labelChanged = true; } else { QgsDebugMsg( QString( "Pin failed for layer, label: %0, %1" ).arg( labellyr, labeltxt ) ); } } } if ( labelChanged ) { mCanvas->refresh(); if ( !mShowPinned ) { // toggle it on (pin-unpin tool doesn't work well without it) QgisApp::instance()->actionShowPinnedLabels()->setChecked( true ); } } }
QFont QgsMapToolLabel::labelFontCurrentFeature() { QFont font; QgsVectorLayer* vlayer = currentLayer(); bool labelSettingsOk; QgsPalLayerSettings& layerSettings = currentLabelSettings( &labelSettingsOk ); if ( labelSettingsOk && vlayer ) { font = layerSettings.textFont; QgsFeature f; if ( vlayer->featureAtId( mCurrentLabelPos.featureId, f, false, true ) ) { const QgsAttributeMap& attributes = f.attributeMap(); QMap< QgsPalLayerSettings::DataDefinedProperties, int > ddProperties = layerSettings.dataDefinedProperties; //size QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator sizeIt = ddProperties.find( QgsPalLayerSettings::Size ); if ( sizeIt != ddProperties.constEnd() ) { if ( layerSettings.fontSizeInMapUnits ) { font.setPixelSize( layerSettings.sizeToPixel( attributes[*sizeIt].toDouble(), QgsRenderContext() ) ); } else { font.setPointSizeF( attributes[*sizeIt].toDouble() ); } } //family QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator familyIt = ddProperties.find( QgsPalLayerSettings::Family ); if ( familyIt != ddProperties.constEnd() ) { font.setFamily( attributes[*sizeIt].toString() ); } //underline QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator underlineIt = ddProperties.find( QgsPalLayerSettings::Underline ); if ( familyIt != ddProperties.constEnd() ) { font.setUnderline( attributes[*underlineIt].toBool() ); } //strikeout QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator strikeoutIt = ddProperties.find( QgsPalLayerSettings::Strikeout ); if ( strikeoutIt != ddProperties.constEnd() ) { font.setStrikeOut( attributes[*strikeoutIt].toBool() ); } //bold QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator boldIt = ddProperties.find( QgsPalLayerSettings::Bold ); if ( boldIt != ddProperties.constEnd() ) { font.setBold( attributes[*boldIt].toBool() ); } //italic QMap< QgsPalLayerSettings::DataDefinedProperties, int >::const_iterator italicIt = ddProperties.find( QgsPalLayerSettings::Italic ); if ( italicIt != ddProperties.constEnd() ) { font.setItalic( attributes[*italicIt].toBool() ); } } } return font; }