00001
00002
00003 #include "VisFramework/VisFrameworkBase/interface/VisQueuedTwig.h"
00004 #include "VisFramework/VisFrameworkBase/interface/debug.h"
00005 #include "VisFramework/VisConfigService/interface/VisConfigurationService.h"
00006 #include "Iguana/GLModels/interface/IgCommon3DReps.h"
00007 #include "Iguana/GLModels/interface/Ig2DModel.h"
00008 #include "Iguana/GLModels/interface/Ig2DRep.h"
00009 #include "Iguana/Inventor/interface/IgSurfaceOperation.h"
00010 #include "Iguana/Studio/interface/IgQtLock.h"
00011 #include "Iguana/Framework/interface/IgRepSet.h"
00012 #include <Inventor/actions/SoGetBoundingBoxAction.h>
00013 #include <Inventor/actions/SoSearchAction.h>
00014 #include <Inventor/nodes/SoMaterial.h>
00015 #include <Inventor/nodes/SoSeparator.h>
00016 #include <qregexp.h>
00017
00018
00019
00020
00021
00022 class VisQueuedTwig::ExactMatch
00023 {
00024 std::string m_name;
00025
00026 public:
00027 ExactMatch (std::string name) : m_name (name) {}
00028
00029 bool operator() (const std::string twig)
00030 {
00031 QRegExp rx (twig);
00032 rx.setWildcard (true);
00033 rx.setCaseSensitive (false);
00034 return rx.exactMatch (m_name);
00035 }
00036 };
00037
00038
00039
00040
00041
00042
00043
00044
00045 VisQueuedTwig::VisQueuedTwig (IgState *state, IgTwig *parent,
00046 const std::string &name )
00047 : IgSimpleTwig (parent, name, true, false, true),
00048 VisEventObserver (state),
00049 m_state (state)
00050 {
00051 ASSERT (m_state);
00052 const edm::ParameterSet *pset = VisConfigurationService::pSet ();
00053 if (pset)
00054 {
00055 std::vector<std::string> twigs;
00056 twigs = pset->getUntrackedParameter<std::vector<std::string> > ("EnabledTwigs", twigs);
00057
00058 if (std::find_if (twigs.begin (), twigs.end (), ExactMatch (fullName ())) != twigs.end ())
00059 selfVisible (true);
00060 }
00061 }
00062
00063 void
00064 VisQueuedTwig::onNewEvent (const edm::Event &, const edm::EventSetup &)
00065 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00066 << "]::onNewEvent(edm::Event,edm::EventSetup)\n");}
00067
00068 void
00069 VisQueuedTwig::onBaseInvalidate (void)
00070 {
00071 LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00072 << "]::onBaseInvalidate()\n");
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083 IgQtLock ();
00084
00085 IgRepSet::invalidate (this, SELF_MASK);
00086 }
00087
00088 void
00089 VisQueuedTwig::onException (lat::Callback1<std::exception *> callback)
00090 {
00091 LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00092 << "]::onException()\n");
00093
00094 m_onException = callback;
00095 }
00096
00097 void
00098 VisQueuedTwig::onUnhandledException (lat::Callback callback)
00099 {
00100 LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00101 << "]::onUnhandledException()\n");
00102
00103 m_onUnhandledException = callback;
00104 }
00105
00106 void
00107 VisQueuedTwig::onError (lat::Callback1<lat::Error *> callback)
00108 {
00109 LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00110 << "]::onError()\n");
00111
00112 m_onError = callback;
00113 }
00114
00115 void
00116 VisQueuedTwig::onCmsException (lat::Callback1<cms::Exception *> callback)
00117 {
00118 LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00119 << "]::onCmsException()\n");
00120
00121 m_onCmsException = callback;
00122 }
00123
00125 void
00126 VisQueuedTwig::update (Ig3DRep *)
00127 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00128 << "]::update(Ig3DRep)\n"); }
00129
00130 void
00131 VisQueuedTwig::update (Ig2DRep *rep)
00132 {
00133
00134 LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00135 << "]::update(Ig2DRep)\n");
00136
00137 Ig2DModel *model = dynamic_cast <Ig2DModel *> (rep->model ());
00138 ASSERT (model);
00139 ASSERT (model->sourceModel ());
00140
00141
00142
00143
00144 Ig3DBaseRep *sourceRep
00145 = static_cast<Ig3DBaseRep *>
00146 (IgRepSet::lookup (this, model->sourceModel ()));
00147
00148 rep->clear ();
00149
00150 if (sourceRep)
00151 {
00152 static SbViewportRegion viewportRegion (640, 480);
00153 static SoGetBoundingBoxAction bbAction(viewportRegion);
00154
00155
00156 SoSearchAction getMaterialAction;
00157 getMaterialAction.setType (SoMaterial::getClassTypeId ());
00158 getMaterialAction.apply (sourceRep->node ());
00159 if (getMaterialAction.getPath () != 0)
00160 rep->node ()->addChild
00161 (getMaterialAction.getPath ()->getTail ());
00162
00163
00164
00165
00166
00167 SoSeparator *sep = new SoSeparator;
00168 sep->addChild (model->cutTransform ());
00169 sep->addChild (sourceRep->node ());
00170 sep->ref ();
00171
00172
00173
00174
00175
00176 bbAction.apply (sep);
00177 SbBox3f sourceBox = bbAction.getBoundingBox ();
00178
00179 SbVec3f sourceCenter = sourceBox.getCenter ();
00180 SbVec3f dimensions = sourceBox.getMax () - sourceCenter;
00181 float sourceSizeWidth = fabs (dimensions [0]);
00182 float sourceSizeHeight = fabs (dimensions [1]);
00183
00184 model->setCutPlanePosition (sourceCenter[0], sourceCenter[1]);
00185 model->setCutPlaneSize (sourceSizeWidth*2,
00186 sourceSizeHeight*2);
00187
00188
00189
00190 IgSurfaceOperation cutOperation (IgSurfaceOperation::SURFACE_1_IN_2);
00191 SoNode *result = cutOperation.apply (model->cutPlane (), sep);
00192 result->ref ();
00193
00194 SoSeparator *resultSep = new SoSeparator;
00195 resultSep->addChild (result);
00196 rep->node ()->addChild (resultSep);
00197 }
00198 }
00199
00200 void
00201 VisQueuedTwig::update (IgLegoRep *)
00202 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00203 << "]::update(IgLegoRep)\n"); }
00204
00205 void
00206 VisQueuedTwig::update (IgTextRep *)
00207 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00208 << "]::update(IgTextRep)\n"); }
00209
00210 void
00211 VisQueuedTwig::update (IgRPhiRep *)
00212 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00213 << "]::update(IgRPhiRep)\n"); }
00214
00215
00216 void
00217 VisQueuedTwig::update (IgRZRep *)
00218 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00219 << "]::update(IgRZRep)\n"); }
00220 void
00221 VisQueuedTwig::update (IgSpareRep *)
00222 { LOG (0, trace, LFfwvis, "VisQueuedTwig[" << name ()
00223 << "]::update(IgSpareRep)\n"); }
00224