00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "solver.hxx"
00030 #include "tool/global.hxx"
00031 #include "dialog.hxx"
00032 #include "lpbuilder.hxx"
00033 #include "xcalc.hxx"
00034 #include "option.hxx"
00035 #include "resmgr.hxx"
00036 #include "solvemodel.hxx"
00037 #include "numeric/matrix.hxx"
00038
00039 #include "cppuhelper/implementationentry.hxx"
00040 #include "com/sun/star/lang/XComponent.hpp"
00041 #include "com/sun/star/frame/XDispatch.hpp"
00042
00043 #include <memory>
00044
00045 using ::rtl::OUString;
00046
00047 namespace scsolver {
00048
00049
00050
00051
00052 static uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames_SolverImpl();
00053 static rtl::OUString getImplementationName_SolverImpl();
00054 static Reference< uno::XInterface > SAL_CALL create_SolverImpl(
00055 Reference< uno::XComponentContext > const & xContext )
00056 SAL_THROW( () );
00057
00058
00059 SolverImpl::SolverImpl( Reference< uno::XComponentContext > const & xContext ) :
00060 #ifndef SCSOLVER_UNO_COMPONENT
00061 m_pResMgr(NULL),
00062 #endif
00063 m_pDlg(NULL),
00064 m_pCalc(new CalcInterface(xContext)),
00065 m_pOption(new OptionData),
00066 m_pStringResMgr(new StringResMgr(m_pCalc.get()))
00067 {
00068 }
00069
00070 SolverImpl::~SolverImpl()
00071 {
00072 }
00073
00074
00075
00076
00077 void SolverImpl::initialize( const Sequence< Any >& ) throw( Exception )
00078 {
00079 }
00080
00081 rtl::OUString SolverImpl::getImplementationName()
00082 throw( RuntimeException )
00083 {
00084 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLEMENTATION_NAME) );
00085 }
00086
00087 sal_Bool SolverImpl::supportsService( rtl::OUString const & serviceName )
00088 throw( RuntimeException )
00089 {
00090 return serviceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(SERVICE_NAME) );
00091 }
00092
00093 Sequence< rtl::OUString > SolverImpl::getSupportedServiceNames()
00094 throw( RuntimeException )
00095 {
00096 return getSupportedServiceNames_SolverImpl();
00097 }
00098
00099 Reference< frame::XDispatch > SAL_CALL SolverImpl::queryDispatch(
00100 const util::URL& aURL, const ::rtl::OUString& , sal_Int32 )
00101 throw ( RuntimeException )
00102 {
00103 Reference< frame::XDispatch > xRet;
00104 if ( aURL.Protocol.compareToAscii("org.go-oo.comp.CalcSolver:") == 0 )
00105 {
00106 if ( aURL.Path.compareToAscii("execute") == 0 )
00107 xRet = this;
00108 }
00109 return xRet;
00110 }
00111
00112 Sequence< Reference< frame::XDispatch > > SAL_CALL SolverImpl::queryDispatches(
00113 const Sequence< frame::DispatchDescriptor >& seqDescripts )
00114 throw ( RuntimeException )
00115 {
00116 sal_Int32 nCount = seqDescripts.getLength();
00117 Sequence< Reference< frame::XDispatch > > lDispatcher( nCount );
00118
00119 for ( sal_Int32 i = 0; i < nCount; ++i )
00120 lDispatcher[i] = queryDispatch(
00121 seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags );
00122
00123 return lDispatcher;
00124 }
00125
00126 void SAL_CALL SolverImpl::dispatch(
00127 const util::URL& aURL, const Sequence< beans::PropertyValue >& )
00128 throw ( RuntimeException )
00129 {
00130 if ( aURL.Protocol.compareToAscii( "org.go-oo.comp.CalcSolver:" ) == 0 )
00131 {
00132 if ( aURL.Path.compareToAscii( "execute" ) == 0 )
00133 {
00134 execute();
00135 }
00136 }
00137 }
00138
00139 void SAL_CALL SolverImpl::addStatusListener(
00140 const Reference< frame::XStatusListener >& , const util::URL& )
00141 throw ( RuntimeException )
00142 {
00143 }
00144
00145 void SAL_CALL SolverImpl::removeStatusListener(
00146 const Reference< frame::XStatusListener >& , const util::URL& )
00147 throw ( RuntimeException )
00148 {
00149 }
00150
00151 void SAL_CALL SolverImpl::dispatchWithNotification(
00152 const util::URL& , const Sequence< beans::PropertyValue >& ,
00153 const Reference< frame::XDispatchResultListener >& )
00154 throw ( RuntimeException )
00155 {
00156 }
00157
00158 SolverDialog* SolverImpl::getMainDialog()
00159 {
00160 if ( m_pDlg.get() == NULL )
00161 m_pDlg.reset( new SolverDialog( this ) );
00162
00163 return m_pDlg.get();
00164 }
00165
00166 CalcInterface* SolverImpl::getCalcInterface() const
00167 {
00168 return m_pCalc.get();
00169 }
00170
00171 OptionData* SolverImpl::getOptionData() const
00172 {
00173 return m_pOption.get();
00174 }
00175
00176 void SolverImpl::setTitle( const ::rtl::OUString& )
00177 throw (uno::RuntimeException)
00178 {
00179 }
00180
00181 sal_Int16 SolverImpl::execute()
00182 throw (::com::sun::star::uno::RuntimeException)
00183 {
00184 getMainDialog()->setVisible( true );
00185 return 0;
00186 }
00187
00188 sal_Bool SolverImpl::solveModel()
00189 {
00190 Debug("solveModel --------------------------------------------------------");
00191
00192 ::std::auto_ptr<SolveModel> p( new SolveModel( this ) );
00193 try
00194 {
00195 p->solve();
00196 }
00197 catch( const RuntimeError& e )
00198 {
00199 getMainDialog()->showMessage( e.getMessage() );
00200 }
00201
00202 if ( p->isSolved() )
00203 {
00204 Debug( "solution available" );
00205 return true;
00206 }
00207
00208 return false;
00209 }
00210
00211 void SolverImpl::initLocale()
00212 {
00213 #ifndef SCSOLVER_UNO_COMPONENT
00214 rtl::OString aModName( "scsolver" );
00215 aModName += rtl::OString::valueOf( sal_Int32( SUPD ) );
00216
00217 m_pResMgr.reset(ResMgr::CreateResMgr(aModName.getStr(), m_eLocale));
00218 #endif
00219 }
00220
00221 #ifndef SCSOLVER_UNO_COMPONENT
00222 ResMgr* SolverImpl::getResMgr()
00223 {
00224 if ( !m_pResMgr.get() )
00225 initLocale();
00226 return m_pResMgr.get();
00227 }
00228 #endif
00229
00230 OUString SolverImpl::getResStr( int resid )
00231 {
00232 #ifdef SCSOLVER_UNO_COMPONENT
00233 return m_pStringResMgr->getLocaleStr(resid);
00234 #else
00235 ResMgr *pResMgr = getResMgr();
00236 if ( pResMgr )
00237 return OUString( String( ResId( resid, *getResMgr() ) ) );
00238 else
00239 return OUString();
00240 #endif
00241 }
00242
00243
00244
00245 void SAL_CALL SolverImpl::setLocale( const lang::Locale& eLocale )
00246 throw(::com::sun::star::uno::RuntimeException)
00247 {
00248 m_eLocale = eLocale;
00249 initLocale();
00250 }
00251
00252 lang::Locale SAL_CALL SolverImpl::getLocale()
00253 throw(::com::sun::star::uno::RuntimeException)
00254 {
00255 return m_eLocale;
00256 }
00257
00258
00259
00260
00261 static Sequence< rtl::OUString > getSupportedServiceNames_SolverImpl()
00262 {
00263 static Sequence < rtl::OUString > *pNames = 0;
00264 if( !pNames )
00265 {
00266 static Sequence< rtl::OUString > seqNames(1);
00267 seqNames.getArray()[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICE_NAME));
00268 pNames = &seqNames;
00269 }
00270 return *pNames;
00271 }
00272
00273 static rtl::OUString getImplementationName_SolverImpl()
00274 {
00275 static rtl::OUString *pImplName = 0;
00276 if( !pImplName )
00277 {
00278 static rtl::OUString implName(
00279 RTL_CONSTASCII_USTRINGPARAM(IMPLEMENTATION_NAME));
00280 pImplName = &implName;
00281 }
00282 return *pImplName;
00283 }
00284
00285 static Reference< uno::XInterface > SAL_CALL create_SolverImpl(
00286 Reference< uno::XComponentContext > const & xContext )
00287 SAL_THROW( () )
00288 {
00289 return static_cast< lang::XTypeProvider * >( new SolverImpl( xContext ) );
00290 }
00291
00292
00293 static struct ::cppu::ImplementationEntry s_component_entries [] =
00294 {
00295 {
00296 create_SolverImpl, getImplementationName_SolverImpl,
00297 getSupportedServiceNames_SolverImpl, ::cppu::createSingleComponentFactory,
00298 0, 0
00299 },
00300 { 0, 0, 0, 0, 0, 0 }
00301 };
00302
00303
00304 }
00305
00306
00307
00308
00309
00310 extern "C"
00311 {
00312 void SAL_DLLPUBLIC_EXPORT component_getImplementationEnvironment(
00313 sal_Char const ** ppEnvTypeName, uno_Environment ** )
00314 {
00315 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
00316 }
00317
00318 sal_Bool SAL_DLLPUBLIC_EXPORT component_writeInfo(
00319 lang::XMultiServiceFactory * xMgr, registry::XRegistryKey * xRegistry )
00320 {
00321 return ::cppu::component_writeInfoHelper(
00322 xMgr, xRegistry, ::scsolver::s_component_entries );
00323 }
00324
00325 void SAL_DLLPUBLIC_EXPORT *component_getFactory(
00326 sal_Char const * implName, lang::XMultiServiceFactory * xMgr,
00327 registry::XRegistryKey * xRegistry )
00328 {
00329 return ::cppu::component_getFactoryHelper(
00330 implName, xMgr, xRegistry, ::scsolver::s_component_entries );
00331 }
00332 }