LCOV - code coverage report
Current view: top level - chart2/source/controller/dialogs - tp_3D_SceneAppearance.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 162 0.6 %
Date: 2015-06-13 12:38:46 Functions: 2 20 10.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "tp_3D_SceneAppearance.hxx"
      21             : #include "ChartModelHelper.hxx"
      22             : #include "ThreeDHelper.hxx"
      23             : #include "macros.hxx"
      24             : #include <rtl/math.hxx>
      25             : #include <com/sun/star/beans/XPropertySet.hpp>
      26             : 
      27             : using namespace ::com::sun::star;
      28             : 
      29             : namespace
      30             : {
      31             : 
      32             : struct lcl_ModelProperties
      33             : {
      34             :     drawing::ShadeMode        m_aShadeMode;
      35             :     sal_Int32                 m_nRoundedEdges;
      36             :     sal_Int32                 m_nObjectLines;
      37             :     ::chart::ThreeDLookScheme m_eScheme;
      38             : 
      39           0 :     lcl_ModelProperties()
      40             :         : m_aShadeMode(drawing::ShadeMode_FLAT)
      41             :         , m_nRoundedEdges(-1)
      42             :         , m_nObjectLines(-1)
      43           0 :         , m_eScheme(::chart::ThreeDLookScheme_Unknown)
      44           0 :     {}
      45             : };
      46             : 
      47           0 : lcl_ModelProperties lcl_getPropertiesFromModel( uno::Reference< frame::XModel > & xModel )
      48             : {
      49           0 :     lcl_ModelProperties aProps;
      50             :     try
      51             :     {
      52           0 :         uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( xModel ) );
      53           0 :         uno::Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY_THROW );
      54           0 :         xDiaProp->getPropertyValue( "D3DSceneShadeMode" ) >>= aProps.m_aShadeMode;
      55           0 :         ::chart::ThreeDHelper::getRoundedEdgesAndObjectLines( xDiagram, aProps.m_nRoundedEdges, aProps.m_nObjectLines );
      56           0 :         aProps.m_eScheme = ::chart::ThreeDHelper::detectScheme( xDiagram );
      57             :     }
      58           0 :     catch( const uno::Exception & ex )
      59             :     {
      60             :         ASSERT_EXCEPTION( ex );
      61             :     }
      62           0 :     return aProps;
      63             : }
      64             : 
      65           0 : void lcl_setShadeModeAtModel( uno::Reference< frame::XModel > & xModel, drawing::ShadeMode aShadeMode )
      66             : {
      67             :     try
      68             :     {
      69             :         uno::Reference< beans::XPropertySet > xDiaProp(
      70           0 :             ::chart::ChartModelHelper::findDiagram( xModel ), uno::UNO_QUERY_THROW );
      71           0 :         xDiaProp->setPropertyValue( "D3DSceneShadeMode" , uno::makeAny( aShadeMode ));
      72             :     }
      73           0 :     catch( const uno::Exception & ex )
      74             :     {
      75             :         ASSERT_EXCEPTION( ex );
      76             :     }
      77           0 : }
      78             : 
      79             : } // anonymous namespace
      80             : 
      81             : namespace chart
      82             : {
      83             : 
      84             : #define POS_3DSCHEME_SIMPLE    0
      85             : #define POS_3DSCHEME_REALISTIC 1
      86             : #define POS_3DSCHEME_CUSTOM 2
      87             : 
      88           0 : ThreeD_SceneAppearance_TabPage::ThreeD_SceneAppearance_TabPage(
      89             :       vcl::Window* pWindow
      90             :     , const uno::Reference< frame::XModel > & xChartModel
      91             :     , ControllerLockHelper & rControllerLockHelper )
      92             :                 : TabPage ( pWindow
      93             :                            , "tp_3D_SceneAppearance"
      94             :                            , "modules/schart/ui/tp_3D_SceneAppearance.ui")
      95             :                 , m_xChartModel     ( xChartModel )
      96             :                 , m_bUpdateOtherControls( true )
      97             :                 , m_bCommitToModel( true )
      98           0 :                 , m_rControllerLockHelper( rControllerLockHelper )
      99             : {
     100             : 
     101           0 :     get(m_pLB_Scheme, "LB_SCHEME");
     102           0 :     get(m_pCB_Shading, "CB_SHADING");
     103           0 :     get(m_pCB_ObjectLines, "CB_OBJECTLINES");
     104           0 :     get(m_pCB_RoundedEdge, "CB_ROUNDEDEDGE");
     105             : 
     106           0 :     m_aCustom = m_pLB_Scheme->GetEntry(POS_3DSCHEME_CUSTOM);
     107           0 :     m_pLB_Scheme->RemoveEntry(POS_3DSCHEME_CUSTOM);
     108           0 :     m_pLB_Scheme->SetDropDownLineCount(2);
     109             : 
     110           0 :     m_pLB_Scheme->SetSelectHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectSchemeHdl ) );
     111             : 
     112           0 :     m_pCB_RoundedEdge->SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
     113           0 :     m_pCB_Shading->SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectShading ) );
     114           0 :     m_pCB_ObjectLines->SetToggleHdl( LINK( this, ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines ) );
     115             : 
     116           0 :     m_pCB_RoundedEdge->EnableTriState( true );
     117           0 :     m_pCB_Shading->EnableTriState( true );
     118           0 :     m_pCB_ObjectLines->EnableTriState( true );
     119             : 
     120           0 :     initControlsFromModel();
     121           0 : }
     122             : 
     123           0 : ThreeD_SceneAppearance_TabPage::~ThreeD_SceneAppearance_TabPage()
     124             : {
     125           0 :     disposeOnce();
     126           0 : }
     127             : 
     128           0 : void ThreeD_SceneAppearance_TabPage::dispose()
     129             : {
     130           0 :     m_pLB_Scheme.clear();
     131           0 :     m_pCB_Shading.clear();
     132           0 :     m_pCB_ObjectLines.clear();
     133           0 :     m_pCB_RoundedEdge.clear();
     134           0 :     TabPage::dispose();
     135           0 : }
     136             : 
     137           0 : void ThreeD_SceneAppearance_TabPage::ActivatePage()
     138             : {
     139           0 :     updateScheme();
     140           0 : }
     141             : 
     142           0 : void ThreeD_SceneAppearance_TabPage::applyRoundedEdgeAndObjectLinesToModel()
     143             : {
     144           0 :     if(!m_bCommitToModel)
     145           0 :         return;
     146             : 
     147           0 :     sal_Int32 nObjectLines = -1;
     148             : 
     149           0 :     switch( m_pCB_ObjectLines->GetState())
     150             :     {
     151             :         case TRISTATE_FALSE:
     152           0 :             nObjectLines = 0;
     153           0 :             break;
     154             :         case TRISTATE_TRUE:
     155           0 :             nObjectLines = 1;
     156           0 :             break;
     157             :         case TRISTATE_INDET:
     158           0 :             nObjectLines = -1;
     159           0 :             break;
     160             :     }
     161             : 
     162           0 :     sal_Int32 nCurrentRoundedEdges = -1;
     163           0 :     switch( m_pCB_RoundedEdge->GetState() )
     164             :     {
     165             :         case TRISTATE_FALSE:
     166           0 :             nCurrentRoundedEdges = 0;
     167           0 :             break;
     168             :         case TRISTATE_TRUE:
     169           0 :             nCurrentRoundedEdges = 5;
     170           0 :             break;
     171             :         case TRISTATE_INDET:
     172           0 :             nCurrentRoundedEdges = -1;
     173           0 :             break;
     174             :     }
     175             : 
     176             :     // locked controllers
     177           0 :     ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     178             :     ThreeDHelper::setRoundedEdgesAndObjectLines(
     179           0 :         ::chart::ChartModelHelper::findDiagram( m_xChartModel ), nCurrentRoundedEdges, nObjectLines );
     180             : }
     181             : 
     182           0 : void ThreeD_SceneAppearance_TabPage::applyShadeModeToModel()
     183             : {
     184           0 :     if(!m_bCommitToModel)
     185           0 :         return;
     186             : 
     187           0 :     drawing::ShadeMode aShadeMode = drawing::ShadeMode_PHONG;
     188             : 
     189           0 :     switch( m_pCB_Shading->GetState())
     190             :     {
     191             :         case TRISTATE_FALSE:
     192           0 :             aShadeMode = drawing::ShadeMode_FLAT;
     193           0 :             break;
     194             :         case TRISTATE_TRUE:
     195           0 :             aShadeMode = drawing::ShadeMode_SMOOTH;
     196           0 :             break;
     197             :         case TRISTATE_INDET:
     198             :             // nothing
     199           0 :             break;
     200             :     }
     201             : 
     202           0 :     lcl_setShadeModeAtModel( m_xChartModel, aShadeMode );
     203             : }
     204             : 
     205           0 : void ThreeD_SceneAppearance_TabPage::initControlsFromModel()
     206             : {
     207           0 :     m_bCommitToModel = false;
     208           0 :     m_bUpdateOtherControls = false;
     209             : 
     210           0 :     lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
     211             : 
     212           0 :     if(aProps.m_aShadeMode == drawing::ShadeMode_FLAT)
     213             :     {
     214           0 :         m_pCB_Shading->EnableTriState( false );
     215           0 :         m_pCB_Shading->Check(false);
     216             :     }
     217           0 :     else if(aProps.m_aShadeMode == drawing::ShadeMode_SMOOTH)
     218             :     {
     219           0 :         m_pCB_Shading->EnableTriState( false );
     220           0 :         m_pCB_Shading->Check(true);
     221             :     }
     222             :     else
     223             :     {
     224           0 :         m_pCB_Shading->EnableTriState( true );
     225           0 :         m_pCB_Shading->SetState( TRISTATE_INDET );
     226             :     }
     227             : 
     228           0 :     if(aProps.m_nObjectLines == 0)
     229             :     {
     230           0 :         m_pCB_ObjectLines->EnableTriState( false );
     231           0 :         m_pCB_ObjectLines->Check(false);
     232             :     }
     233           0 :     else if(aProps.m_nObjectLines==1)
     234             :     {
     235           0 :         m_pCB_ObjectLines->EnableTriState( false );
     236           0 :         m_pCB_ObjectLines->Check(true);
     237             :     }
     238             :     else
     239             :     {
     240           0 :         m_pCB_ObjectLines->EnableTriState( true );
     241           0 :         m_pCB_ObjectLines->SetState( TRISTATE_INDET );
     242             :     }
     243             : 
     244           0 :     if(aProps.m_nRoundedEdges >= 5)
     245             :     {
     246           0 :         m_pCB_RoundedEdge->EnableTriState( false );
     247           0 :         m_pCB_RoundedEdge->Check(true);
     248             :     }
     249           0 :     else if(aProps.m_nRoundedEdges<0)
     250             :     {
     251           0 :         m_pCB_RoundedEdge->EnableTriState( false );
     252           0 :         m_pCB_RoundedEdge->SetState( TRISTATE_INDET );
     253             :     }
     254             :     else
     255             :     {
     256           0 :         m_pCB_RoundedEdge->EnableTriState( true );
     257           0 :         m_pCB_RoundedEdge->Check(false);
     258             :     }
     259           0 :     m_pCB_RoundedEdge->Enable( !m_pCB_ObjectLines->IsChecked() );
     260             : 
     261           0 :     updateScheme();
     262             : 
     263           0 :     m_bCommitToModel = true;
     264           0 :     m_bUpdateOtherControls = true;
     265           0 : }
     266             : 
     267           0 : void ThreeD_SceneAppearance_TabPage::updateScheme()
     268             : {
     269           0 :     lcl_ModelProperties aProps( lcl_getPropertiesFromModel( m_xChartModel ));
     270             : 
     271           0 :     if( m_pLB_Scheme->GetEntryCount() == (POS_3DSCHEME_CUSTOM+1) )
     272             :     {
     273           0 :         m_pLB_Scheme->RemoveEntry(POS_3DSCHEME_CUSTOM);
     274           0 :         m_pLB_Scheme->SetDropDownLineCount(2);
     275             :     }
     276           0 :     switch( aProps.m_eScheme )
     277             :     {
     278             :         case ThreeDLookScheme_Simple:
     279           0 :             m_pLB_Scheme->SelectEntryPos( POS_3DSCHEME_SIMPLE );
     280           0 :             break;
     281             :         case ThreeDLookScheme_Realistic:
     282           0 :             m_pLB_Scheme->SelectEntryPos( POS_3DSCHEME_REALISTIC );
     283           0 :             break;
     284             :         case ThreeDLookScheme_Unknown:
     285             :             {
     286           0 :                 m_pLB_Scheme->InsertEntry(m_aCustom,POS_3DSCHEME_CUSTOM);
     287           0 :                 m_pLB_Scheme->SelectEntryPos( POS_3DSCHEME_CUSTOM );
     288           0 :                 m_pLB_Scheme->SetDropDownLineCount(3);
     289             :             }
     290           0 :             break;
     291             :     }
     292           0 : }
     293             : 
     294           0 : IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectSchemeHdl)
     295             : {
     296           0 :     if( !m_bUpdateOtherControls )
     297           0 :         return 0;
     298             : 
     299             :     {
     300             :         // locked controllers
     301           0 :         ControllerLockHelperGuard aGuard( m_rControllerLockHelper );
     302             : 
     303           0 :         uno::Reference< chart2::XDiagram > xDiagram( ::chart::ChartModelHelper::findDiagram( m_xChartModel ) );
     304             : 
     305           0 :         if( m_pLB_Scheme->GetSelectEntryPos() == POS_3DSCHEME_REALISTIC )
     306           0 :             ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Realistic );
     307           0 :         else if( m_pLB_Scheme->GetSelectEntryPos() == POS_3DSCHEME_SIMPLE )
     308           0 :             ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Simple );
     309             :         else
     310             :         {
     311             :             OSL_FAIL( "Invalid Entry selected" );
     312           0 :         }
     313             :     }
     314             : 
     315             :     // update other controls
     316           0 :     initControlsFromModel();
     317           0 :     return 0;
     318             : }
     319             : 
     320           0 : IMPL_LINK_NOARG(ThreeD_SceneAppearance_TabPage, SelectShading)
     321             : {
     322           0 :     if( !m_bUpdateOtherControls )
     323           0 :         return 0;
     324             : 
     325           0 :     m_pCB_Shading->EnableTriState( false );
     326           0 :     applyShadeModeToModel();
     327           0 :     updateScheme();
     328           0 :     return 0;
     329             : }
     330           0 : IMPL_LINK( ThreeD_SceneAppearance_TabPage, SelectRoundedEdgeOrObjectLines, CheckBox*, pCheckBox )
     331             : {
     332           0 :     if( !m_bUpdateOtherControls )
     333           0 :         return 0;
     334             : 
     335           0 :     if( pCheckBox == m_pCB_ObjectLines )
     336             :     {
     337           0 :         m_pCB_ObjectLines->EnableTriState( false );
     338           0 :         m_bUpdateOtherControls = false;
     339           0 :         m_pCB_RoundedEdge->Enable( !m_pCB_ObjectLines->IsChecked() );
     340           0 :         if(!m_pCB_RoundedEdge->IsEnabled())
     341           0 :             m_pCB_RoundedEdge->Check(false);
     342           0 :         m_bUpdateOtherControls = true;
     343             :     }
     344             :     else
     345           0 :         m_pCB_RoundedEdge->EnableTriState( false );
     346           0 :     applyRoundedEdgeAndObjectLinesToModel();
     347           0 :     updateScheme();
     348           0 :     return 0;
     349             : }
     350             : 
     351          57 : } //namespace chart
     352             : 
     353             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11