Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoXtMaterialEditor.h
Go to the documentation of this file.
1/*=======================================================================
2 * Copyright 1991-1996, Silicon Graphics, Inc.
3 * ALL RIGHTS RESERVED
4 *
5 * UNPUBLISHED -- Rights reserved under the copyright laws of the United
6 * States. Use of a copyright notice is precautionary only and does not
7 * imply publication or disclosure.
8 *
9 * U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND:
10 * Use, duplication or disclosure by the Government is subject to restrictions
11 * as set forth in FAR 52.227.19(c)(2) or subparagraph (c)(1)(ii) of the Rights
12 * in Technical Data and Computer Software clause at DFARS 252.227-7013 and/or
13 * in similar or successor clauses in the FAR, or the DOD or NASA FAR
14 * Supplement. Contractor/manufacturer is Silicon Graphics, Inc.,
15 * 2011 N. Shoreline Blvd. Mountain View, CA 94039-7311.
16 *
17 * THE CONTENT OF THIS WORK CONTAINS CONFIDENTIAL AND PROPRIETARY
18 * INFORMATION OF SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION,
19 * DISTRIBUTION, OR DISCLOSURE IN ANY FORM, IN WHOLE, OR IN PART, IS STRICTLY
20 * PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN PERMISSION OF SILICON
21 * GRAPHICS, INC.
22**=======================================================================*/
23/*=======================================================================
24** Author : Alain Dumesny (MMM yyyy)
25** Modified by : David Mott (MMM yyyy)
26**=======================================================================*/
27/*=======================================================================
28 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
29 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
30 *** ***
31 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
32 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
33 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
34 *** ***
35 *** RESTRICTED RIGHTS LEGEND ***
36 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
37 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
38 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
39 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
40 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
41 *** ***
42 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, ***
43 *** BORDEAUX, FRANCE ***
44 *** ALL RIGHTS RESERVED ***
45**=======================================================================*/
46/*=======================================================================
47** Modified by : VSG (MMM YYYY)
48**=======================================================================*/
49
50#ifdef SOQT
52#elif defined _WIN32
54#else // _WIN32
55
56#ifndef _SO_XT_MATERIAL_EDITOR_
57#define _SO_XT_MATERIAL_EDITOR_
58
59#include <Xm/Xm.h>
60#include <Inventor/SbBasic.h>
63
64class SoBaseColor;
65class SoXtClipboard;
66class SoXtColorEditor;
67class SoNodeSensor;
68class SoSensor;
70class SoMaterial;
72class SoPathList;
73class SoXtRenderArea;
74class SoSelection;
75class SoXtColorSlider;
76class SoMFColor;
77class SbColor;
78class SoBase;
79class SoSeparator;
80class SoNode;
81class SoSFColor;
82
83// callback function prototypes
84typedef void SoXtMaterialEditorCB(void *userData, const SoMaterial *mtl);
85
87//
88// Class: SoXtMaterialEditor
89//
90// This editor lets you interactively edit a material
91//
93
157 public:
172
177 SoWidget parent = NULL,
178 const char *name = NULL,
179 SbBool buildInsideParent = TRUE);
184
189 void attach(SoMaterial *material, int index = 0);
190
194 void detach();
198 SbBool isAttached() { return (material != NULL); }
199
205 inline void addMaterialChangedCallback(
207 void *userData = NULL);
213 void *userData = NULL);
214
218 void setUpdateFrequency(SoXtMaterialEditor::UpdateFrequency freq);
224
225 // Redefine these since there are multiple windows -
226 // the color editor, directional light editor, and this component
227 virtual void show();
228 virtual void hide();
229
233 void setMaterial(const SoMaterial &mtl);
234
238 const SoMaterial & getMaterial() const { return *localMaterial; }
239
240 private:
241
242 // This constructor takes a boolean whether to build the widget now.
243 // Subclasses can pass FALSE, then call SoXtMaterialEditor::buildWidget()
244 // when they are ready for it to be built.
247 SoWidget parent,
248 const char *name,
249 SbBool buildInsideParent,
250 SbBool buildNow);
251
252 SoWidget buildWidget(SoWidget parent);
253
254 // redefine these
255 virtual SbString getDefaultWidgetName() const;
256 virtual SbString getDefaultTitle() const;
257 virtual SbString getDefaultIconTitle() const;
258
259 private:
260 // attach vars
261 SoMaterial *material; // material we are editing
262 SoMaterial *imat;
263 int index; // material index number
264 SoNodeSensor *sensor;
265 SoCallbackList *callbackList;
266 SoWidget acceptButton, diamondButtons[4], radioButtons[4];
267 SoXtMaterialEditor::UpdateFrequency updateFreq;
268
269 // widgets to edit the material
270 SoWidget mgrWidget; // topmost widget
271 SoXtColorEditor *colorEditor;
272 SoXtColorSlider *sliders[6];
273 SbBool changedIt[6];
274 SoXtMaterialList *materialList;
275 SbBool ignoreCallback; // TRUE while callback should be ignored
276 SbBool openMaterialList;
277 static void colorEditorCloseCB(void *, SoXtComponent *);
278 static void materialListCloseCB(void *, SoXtComponent *);
279
280 // copy/paste support
281 SoXtClipboard *clipboard;
282
283 // local scene vars
284 SoXtRenderArea *renderArea;
285 SoMaterial *localMaterial; // local copy of the material
286 SoDirectionalLight *light0;
287 SoDirectionalLight *light1;
288 SoBaseColor *tileColor;
289 SoSeparator *root;
290
291 // keep the menu items around so we can update them before menu display
292 SoWidget *menuItemsList;
293
294 int32_t activeColor; // field which color editor edits
295
296 // update the sliders/colorEditor based on the local material
297 void updateLocalComponents();
298
299 // update the colorEditor based on the activeColor flag
300 void updateColorEditor(SbBool updateTitle = FALSE);
301
302 // update a color slider (amb/diff/spec/emiss) based of a material color
303 // (split the base color from the intensity).
304 void updateColorSlider(SoXtColorSlider *, const float rgb[3]);
305
306 // update a material field when a color slider changes.
307 void updateMaterialColor(
308 SoMFColor *editMtlColor,
309 SoMFColor *localMtlColor,
310 const float *rgb,
311 float intensity);
312 void updateMaterialColor(
313 SoSFColor *editMtlColor,
314 SoMFColor *localMtlColor,
315 const float *rgb,
316 float intensity);
317
318 // copies mat2 onto mat1
319 void copyMaterial(SoMaterial *mat1, int index1,
320 const SoMaterial *mat2, int index2);
321
322 // For each of the 6 sliders (or sets of sliders) sets the ignore flag of
323 // the material node being editted to FALSE if it has been changed.
324 void undoIgnoresIfChanged();
325
326 // copy/paste support
327 static void pasteDone(void *userData, SoPathList *pathList);
328
329 // Callback routines from components
330 static void materialListCB(void *, const SoMaterial *);
331 static void colorEditorCB(void *, const SbColor *);
332 static void ambientSliderCB(void *, float);
333 static void diffuseSliderCB(void *, float);
334 static void specularSliderCB(void *, float);
335 static void emissiveSliderCB(void *, float);
336 static void shininessSliderCB(void *, float);
337 static void transparencySliderCB(void *, float);
338
339 // Callback routines from Xt/Motif
340 static void menuPick(SoWidget, int, XmAnyCallbackStruct *);
341 static void menuDisplay(SoWidget, SoXtMaterialEditor *, XtPointer);
342 static void radioButtonPick(SoWidget, int, XtPointer);
343 static void diamondButtonPick(SoWidget, int, XtPointer);
344 static void acceptButtonCB(SoWidget, SoXtMaterialEditor *, XtPointer);
345
346 // Sensor callbacks
347 static void sensorCB(void *, SoSensor *);
348
349 // Build routines
350 SoWidget buildPulldownMenu(SoWidget parent);
351 SoWidget buildControls(SoWidget parent);
352 SoWidget buildSlidersForm(SoWidget parent);
353
354 static void visibilityChangeCB(void *pt, SbBool visible);
355 void activate(); // connects the sensor
356 void deactivate(); // disconnects the sensor
357
358 // this is called by both constructors
359 void constructorCommon(SbBool buildNow);
360
361};
362
363
364// Inline functions
365void
368 void *userData)
369{ callbackList->addCallback((SoCallbackListCB *) f, userData); }
370
371void
374 void *userData)
375{ callbackList->removeCallback((SoCallbackListCB *) f, userData); }
376
377#endif // _SO_XT_MATERIAL_EDITOR_
378
379#endif // _WIN32
380
381
#define SoEXTENDER
#define TRUE
Possible value of SbBool.
Definition SbBase.h:77
#define FALSE
Possible value of SbBool.
Definition SbBase.h:75
void * XtPointer
Definition SoQtDef.h:118
#define SoWidget
Definition SoQtDef.h:40
#define XmAnyCallbackStruct
Definition SoWinDef.h:127
void addMaterialChangedCallback(SoWinMaterialPaletteCB *f, void *userData=NULL)
void removeMaterialChangedCallback(SoWinMaterialPaletteCB *f, void *userData=NULL)
#define SoXtMaterialEditorCB
Definition SoXt2SoQt.h:96
#define SoXtColorSlider
Definition SoXt2SoQt.h:175
#define SoXtMaterialEditor
Definition SoXt2SoQt.h:95
void SoXtMaterialEditorCB(void *userData, const SoMaterial *mtl)
Color vector class.
Definition SbColor.h:82
Class for smart character strings.
Definition SbString.h:202
Node that defines an object's base color.
Definition SoBaseColor.h:95
Base class for all nodes, paths, and engines.
Definition SoBase.h:111
Manages a list of callbacks and associated data.
void addCallback(SoCallbackListCB *f, void *userData=NULL)
Adds a function to the list of callback functions.
void removeCallback(SoCallbackListCB *f, void *userData=NULL)
Removes a function from the list of callback functions.
Node representing a directional light source.
Multiple-value field containing any number of RGB colors stored as three floats.
Definition SoMFColor.h:98
Surface material definition node.
Definition SoMaterial.h:186
Abstract base class for all database nodes.
Definition SoNode.h:145
Sensor class that can be attached to Open Inventor nodes.
Maintains a list of pointers to paths.
Definition SoPathList.h:81
Field containing an RGB color.
Definition SoSFColor.h:82
Manages a list of selected objects.
Abstract base class for Open Inventor sensors.
Definition SoSensor.h:97
Group node that saves and restores traversal state.
Supports copy/paste for Open Inventor using the Xt clipboard.
Component that lets you edit a color interactively.
Abstract base class for all Open Inventor components.
Component which lets you edit a material interactively.
void attach(SoMaterial *material, int index=0)
Attaches the editor to a material node and edits the material of the given index.
virtual void hide()
This hides the component.
~SoXtMaterialEditor()
Destructor.
UpdateFrequency
UpdateFrequency is how often new values should be sent to the node or the callback routine.
@ CONTINUOUS
Send updates with every mouse motion.
@ AFTER_ACCEPT
Only send updates after user hits accept button.
const SoMaterial & getMaterial() const
Gets the current material value.
virtual void show()
This shows the component.
SbBool isAttached()
Returns TRUE if the editor is attached.
void addMaterialChangedCallback(SoXtMaterialEditorCB *f, void *userData=NULL)
Additional way of using the material editor, by registering a callback which will be called whenever ...
SoXtMaterialEditor(SoWidget parent=NULL, const char *name=NULL, SbBool buildInsideParent=TRUE)
Constructor.
void detach()
Detaches the editor from the material node.
SoXtMaterialEditor::UpdateFrequency getUpdateFrequency()
Gets the update frequency.
void removeMaterialChangedCallback(SoXtMaterialEditorCB *f, void *userData=NULL)
Removes the material changed callback.
void setMaterial(const SoMaterial &mtl)
Sets a new material value.
void setUpdateFrequency(SoXtMaterialEditor::UpdateFrequency freq)
Sets the update frequency.
Component which lets you edit a material interactively.
Component for rendering Open Inventor scene graphs.
int SbBool
Boolean type.
Definition SbBase.h:87
void SoCallbackListCB(void *userData, void *callbackData)