diff --git a/toonz/sources/include/tools/tool.h b/toonz/sources/include/tools/tool.h index 7346bf9..fde613e 100644 --- a/toonz/sources/include/tools/tool.h +++ b/toonz/sources/include/tools/tool.h @@ -323,8 +323,8 @@ public: bool toBeModified, int subsampling = 0); //!< Returns the image to be edited by the tool. - static TImage *touchImage(); //!< Returns a pointer to the actual image - the - //! one of the frame that has been selected. + TImage *touchImage(); //!< Returns a pointer to the actual image - the + //! one of the frame that has been selected. /*! \details This function is necessary since tools are created before the main diff --git a/toonz/sources/tnztools/editassistantstool.cpp b/toonz/sources/tnztools/editassistantstool.cpp index 8d00997..d89ac37 100644 --- a/toonz/sources/tnztools/editassistantstool.cpp +++ b/toonz/sources/tnztools/editassistantstool.cpp @@ -157,7 +157,7 @@ public: m_writeImage(), m_writeAssistant() { - bind(MetaImage); + bind(MetaImage | EmptyTarget); m_toolProperties.bind(m_assistantType); updateTranslation(); } diff --git a/toonz/sources/tnztools/tool.cpp b/toonz/sources/tnztools/tool.cpp index 36f0e23..eab99e2 100644 --- a/toonz/sources/tnztools/tool.cpp +++ b/toonz/sources/tnztools/tool.cpp @@ -57,7 +57,7 @@ namespace { // Global variables typedef std::pair ToolKey; -typedef std::map ToolTable; +typedef std::multimap ToolTable; ToolTable *toolTable = 0; std::set *toolNames = 0; @@ -181,10 +181,36 @@ TTool::TTool(std::string name) TTool *TTool::getTool(std::string toolName, ToolTargetType targetType) { if (!toolTable) return 0; - ToolTable::iterator it = - toolTable->find(std::make_pair(toolName, targetType)); - if (it == toolTable->end()) return 0; - return it->second; + + // if to this name and target type was assigned more then one tool + // then select tool which more compatible with default target type + + int defTarget = 0; + switch(Preferences::instance()->getDefLevelType()) { + case PLI_XSHLEVEL: defTarget = VectorImage; break; + case TZP_XSHLEVEL: defTarget = ToonzImage; break; + case OVL_XSHLEVEL: defTarget = RasterImage; break; + case META_XSHLEVEL: defTarget = MetaImage; break; + default: defTarget = 0; break; + } + + bool isDefault = false; + int target = 0; + TTool *tool = 0; + + std::pair range = + toolTable->equal_range(std::make_pair(toolName, targetType)); + for(ToolTable::iterator it = range.first; it != range.second; ++it) { + int t = it->second->getTargetType(); + bool d = (bool)(t & defTarget); + if (!tool || (d && !isDefault) || (d == isDefault && t > target)) { + isDefault = d; + target = t; + tool = it->second; + } + } + + return tool; } //----------------------------------------------------------------------------- @@ -202,6 +228,8 @@ void TTool::bind(int targetType) { // Initialize with the dummy tool toolTable->insert( + std::make_pair(std::make_pair(name, EmptyTarget), &theDummyTool)); + toolTable->insert( std::make_pair(std::make_pair(name, ToonzImage), &theDummyTool)); toolTable->insert( std::make_pair(std::make_pair(name, VectorImage), &theDummyTool)); @@ -218,16 +246,24 @@ void TTool::bind(int targetType) { toolSelector, &ToolSelector::selectTool)); } + if (targetType & EmptyTarget) + toolTable->insert( + std::make_pair(std::make_pair(name, EmptyTarget), this)); if (targetType & ToonzImage) - (*toolTable)[std::make_pair(name, ToonzImage)] = this; + toolTable->insert( + std::make_pair(std::make_pair(name, ToonzImage), this)); if (targetType & VectorImage) - (*toolTable)[std::make_pair(name, VectorImage)] = this; + toolTable->insert( + std::make_pair(std::make_pair(name, VectorImage), this)); if (targetType & RasterImage) - (*toolTable)[std::make_pair(name, RasterImage)] = this; + toolTable->insert( + std::make_pair(std::make_pair(name, RasterImage), this)); if (targetType & MeshImage) - (*toolTable)[std::make_pair(name, MeshImage)] = this; + toolTable->insert( + std::make_pair(std::make_pair(name, MeshImage), this)); if (targetType & MetaImage) - (*toolTable)[std::make_pair(name, MetaImage)] = this; + toolTable->insert( + std::make_pair(std::make_pair(name, MetaImage), this)); } //----------------------------------------------------------------------------- @@ -525,7 +561,25 @@ TImage *TTool::touchImage() { // - - - - empty column case starts here - - - - // autoCreate is enabled: we must create a new level - int levelType = pref->getDefLevelType(); + + // select one from supported level types + // default level type is preffered + int levelType = pref->getDefLevelType(); + int toolLevelType = UNKNOWN_XSHLEVEL; + bool found = false; + + if ( m_targetType & MetaImage ) + { toolLevelType = META_XSHLEVEL; found = found || toolLevelType == levelType; } + if ( m_targetType & RasterImage ) + { toolLevelType = OVL_XSHLEVEL; found = found || toolLevelType == levelType; } + if ( m_targetType & ToonzImage ) + { toolLevelType = TZP_XSHLEVEL; found = found || toolLevelType == levelType; } + if ( m_targetType & VectorImage ) + { toolLevelType = PLI_XSHLEVEL; found = found || toolLevelType == levelType; } + + if (toolLevelType == UNKNOWN_XSHLEVEL) return 0; + if (!found) levelType = toolLevelType; + TXshLevel *xl = scene->createNewLevel(levelType); sl = xl->getSimpleLevel(); m_isLevelCreated = true; diff --git a/toonz/sources/tnztools/toolhandle.cpp b/toonz/sources/tnztools/toolhandle.cpp index be4ff6b..c3c1267 100644 --- a/toonz/sources/tnztools/toolhandle.cpp +++ b/toonz/sources/tnztools/toolhandle.cpp @@ -117,7 +117,7 @@ void ToolHandle::changeTool(QAction* action) //----------------------------------------------------------------------------- void ToolHandle::onImageChanged(TImage::Type imageType) { - TTool::ToolTargetType targetType = TTool::NoTarget; + TTool::ToolTargetType targetType = TTool::EmptyTarget; switch (imageType) { case TImage::RASTER: @@ -133,9 +133,11 @@ void ToolHandle::onImageChanged(TImage::Type imageType) { targetType = TTool::MetaImage; break; case TImage::VECTOR: - default: targetType = TTool::VectorImage; break; + default: + targetType = TTool::EmptyTarget; + break; } if (targetType != m_toolTargetType) { diff --git a/toonz/sources/toonz/tapp.cpp b/toonz/sources/toonz/tapp.cpp index a3cb66b..17c2731 100644 --- a/toonz/sources/toonz/tapp.cpp +++ b/toonz/sources/toonz/tapp.cpp @@ -307,11 +307,14 @@ int TApp::getCurrentImageType() { cell = xsh->getCell(r0, col); } else /*-- Columnが空の場合 --*/ { + return TImage::NONE; + /* int levelType = Preferences::instance()->getDefLevelType(); return (levelType == PLI_XSHLEVEL) ? TImage::VECTOR : (levelType == TZP_XSHLEVEL) ? TImage::TOONZ_RASTER : TImage::RASTER; + */ } } @@ -330,12 +333,13 @@ int TApp::getCurrentImageType() { case MESH_XSHLEVEL: return TImage::MESH; case PLI_XSHLEVEL: - default: return TImage::VECTOR; + default: + return TImage::NONE; } } - return TImage::VECTOR; + return TImage::NONE; } //-----------------------------------------------------------------------------